Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide one view and unhide another upon touching a button

I have been creating "if/then" apps for android and now my boss want me to do the same for his iPad. I just need to figure out how to code so that when the buttons are clicked, it hides the current view (text and button) and reveals the next set of text and buttons.

like image 731
philvitz Avatar asked Sep 25 '11 22:09

philvitz


1 Answers

Make sure your two sets of text/buttons are in two UIViews (I will refer to these as 'viewOne' and 'viewTwo'), when you want to swap your views, use this code:

[viewOne setHidden:[viewTwo isHidden]];
[viewTwo setHidden:![viewTwo isHidden]];

It's not the most understandable way to do this, but it's one of the shortest. For something easier to read:

if ([viewOne isHidden]) {
    [viewOne setHidden:NO];
    [viewTwo setHidden:YES];
} else {
    [viewOne setHidden:NO];
    [viewTwo setHidden:YES];
}

Either will work, it just depends on how you like to write your code.

like image 122
Dyldo42 Avatar answered Oct 24 '22 23:10

Dyldo42