I this is my first iphone app. I application shows different view and comes back from minimized mode. I want to identify which of these views is currently shown.
I tried using "isa"
in applicationDidEnterForeground()
event.
However the i think i am not correct.
2 Answers
You could use the tag
property to tag your views and use this to identify particular views. This may be better as the tag
property will identify instances of the classes as opposed to just the class type.
If you want to check the type of class though, you can use the NSObject protocol instance methods:
- (BOOL)isKindOfClass:(Class)aClass
or
- (BOOL)isMemberOfClass:(Class)aClass
You use the class
instance method of an object to return the class of an object. isKindOfClass: returns true if the class of the instance is the same as the one provided (or it is a subclass of that class), where as isMemberOfClass: returns true if the class of the instance is exactly the same as the one provided. For example:
if ([myObject isMemberOfClass:[UITableView class]])
{
// Do stuff
}

- 28,702
- 8
- 57
- 64
-
This info doesn't really help answer his question though -- he needs some way of accessing the currently showing view. – occulus Mar 14 '11 at 08:07
-
Ah sorry, the "isa" bit threw me off. For a question on accessing views from the UIApplicationDelegate class, see the answer I made here: http://stackoverflow.com/questions/5290622/access-method-in-viewcontroller-from-appdelegate/5290755#5290755 – James Bedford Mar 14 '11 at 08:37
Using isa
isn't really the core of this problem as far as I can see -- isa
has to do with class identity, but your core problem here is actually finding out the class instance you need to identify! What were you accessing the isa
property on?
This question may be related though -- in particular this part of my answer:
There's no out of the box way to tell which is the 'current' UIViewController by the way. But you can find ways around that, e.g. there are delegate methods of UINavigationController for finding out when a UIViewController is presented therein. You could use such a thing to track the latest UIViewController which has been presented.
Something which may be useful: since iOS4, UIWindow
has a property rootViewController
which is set to the current root view controller. Obviously, that might be a UINavigationController or some other UIViewController aggregator, so you'd still have to do some work in that case...