0

I am trying to figure out which UIViewController is currently on the top of the UINavigationController stack, I am passing these values over to my NSArray viewCtrls, when I log the top UIViewController I get this.

<SearchViewController: 0x1457c550> 

So this is the code I am trying to use to figure out which UIViewController is at the top of the UINavigationStack

NSArray *viewCtrls = navcontroller.viewControllers; UIViewController *vCtrl = [viewCtrls objectAtIndex:[viewCtrls count]-1]; NSLog(@"%@", vCtrl); if ([vCtrl isKindOfClass:SearchViewController]) { NSLog(@"yes"); } else { NSLog(@"no"); } 

However I am getting this error on the first line of the if statement.

Use of undeclared identifier 'SearchViewController' 

I would like to know how I am supposed to declare the identifier? this is being called from a NSObjectClass, so I need to pass a parameter of self from the UIViewController that called this NSObjec class? or is there a better way of doing it?

2 Answers 2

2

You want [vCtrl isKindOfClass:[SearchViewController class]]

Sign up to request clarification or add additional context in comments.

3 Comments

weird.. its still giving me that same error.. I have cleaned the project and tried rebuilding it..
What is a SearchViewController? Is it your own object? Are you importing the header?
SearchViewController is a UIViewController and it is the UIViewController that calls the NSObject method that my if statement is in. i.e.(SearchViewController calls connectionObjectClass, connectionObjectCLass has the if statement where I am trying to decide what to do with the request. The reason for that is that two different ViewControllers call the same NSObject method so i am trying to differentiate between the two.)
1

Mike's solution should have worked all right. Apparently, it is not able to understand what SearchViewController is, really. Can you check putting a forward declaration

@class SearchViewController 

for the SearchViewController class in the header file of the class where the above code is written, and then importing the SearchViewController.h file in the source file of the class where the above code is written.

#import "SearchViewController.h" 

3 Comments

As soon as I add those two lines of code, the error goes away and is replaced with an error from the calling class saying that it cannot see the NSObjectClass (EngineRequest) I have declared.
These are the errors - Unknown type name 'EngineRequest' and Property with 'retain (or strong)' attribute must be of object type
I have fixed it by changing #import of EngineRequest to @class also. and the if stament now works. I am going to read up a little about (at-class) and why its used.. thanks for your help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.