Finding typeof View
I this is my first iphone app. I application shows different view and comes back from minimized mode. I wan开发者_如何学编程t to identify which of these views is currently shown.
I tried using "isa"
in applicationDidEnterForeground()
event.
However the i think i am not correct.
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
}
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...
精彩评论