How to determine the current view that is displayed

If I have 3 different views that are defined in 3 corresponding functions, namely:

- (UIView *)getView1 { /*...*/ }
- (UIView *)getView2 { /*...*/ }
- (UIView *)getView3 { /*...*/ }

They are added to self.viewwhen a specific view is required.

My question is: how do we know which of these views is currently being displayed? Is there a parameter that will determine which view is current?

+3
source share
3 answers

You can mark each view as an integer, and then read the tag to determine which view is active (assuming you are replacing self.view).

#define TAG_VIEW_1 1
#define TAG_VIEW_2 2
#define TAG_VIEW_3 3
...
[ [self getView1()] setTag:TAG_VIEW_1 ];
[ [self getView2()] setTag:TAG_VIEW_2 ];
[ [self getView3()] setTag:TAG_VIEW_3 ];
...    

if ( self.view.tag == TAG_VIEW_1 ) {
    // do something
}
else if ( self.view.tag == TAG_VIEW_2 ) {
    // etc
}
...
+5
source

, self.view , [self superview], , .

+3

UIView , , . window, , :

BOOL isDisplayed = self.view.window != nil;

willMoveToWindow: UIView, , .

+1

All Articles