Why do my views overlap each other?
I just can't understand the views thing and somehow couldn't find one clear solution.
I have a view "A", and it has a button to go to another view "B". View B takes me to view C and view C takes me back to A.
In view C, everywhere that the user taps, he sees an image appear. The code for that is in view C's .m file.
The problem is that when I switch from view C to A, the code for C is still working on view A? If I tap on A, I see that image everywhere I tap, but A is my menu and not part of the game. The method that makes an image appear on a tap belongs only to view C!
I can't understand these views; at the start I used insertSubview:atIndex:
, and everything was overlapping, so now I use addSubview:
, and I have this problem.
Can some one explain geometrically how this works?
How come the buttons from view C are seen in view A somtimes without reason? Why, after loading C and back to A, it implements the code开发者_StackOverflow of C on view A?
Why do my views overlap all the time? I want every view to work seperately, and not see anything from the views behind it, or implement code from views that were loaded in the past.
Please, help me with my views. Thanks a lot.
Rather than views, you probably want to focus on UIViewControllers. With this you won't have that problem, a UIViewController is almost always fullscreen and you can code specifically for it. You can create three UIViewController subclasses, one for A, B and C. In each's nib you can add a button, and use this to present the next view controller (possibly using presentModalViewController:). In the third subclass, you can implement your logic for showing an image when the user taps.
One good practice, let say you have a
UIViewController *myViewController with 3 properties :
UIVIew *viewA
UIView *viewB
UIView *viewC
When you want to diplay put a viewA on the stack just set
myViewController.view = viewA;
and so on!
精彩评论