How to change view on button click in iPhone without navigation controller?

后端 未结 5 1758
小蘑菇
小蘑菇 2021-01-03 11:54

I want to know how to change view on button click in iPhone without navigation controller?

5条回答
  •  暖寄归人
    2021-01-03 12:11

    Assume you have two view myView1 and myView2 and one button myUIButton in memory

    myView1.tag = 1;
    myView2.tag = 2;
    myUIButton.tag = 1; //Current visible view is myView1
    

    -(void) ButtonCLicked:(id) sender 
    {
           UIButton* myButton = (UIButton*)sender;
    
    
           if(sender.tag == 1)
           {
               [myView1 removeFromSuperview];
               [self addSubview:myView2]
               myButton.tag = myView2.tag;
           }
           else 
          {
              [myView2 removeFromSuperview];
              [self addSubview:myView1]
               myButton.tag = myView1.tag;
          }
    }
    

提交回复
热议问题