switch between uiviews with buttons and not uinavigation controllers

后端 未结 2 1818
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 17:26

I have seen the post for How to switch views by buttons on iPhone? but this doesn\'t answer how to switch back and forth between views with buttons. The person that asked t

2条回答
  •  自闭症患者
    2020-12-30 17:46

    You removed the view controller's view from it's superview and then added a subview to it. The view hierarchy is broken at the view controller's superview (likely your window). That is why you are getting a blank screen.

    You'd likely want to keep a reference around to the original view and then swap it out to the new view by setting the view controller's view to the new view.

    // origView is an instance variable/IBOutlet to your original view.
    - (IBAction)switchToPhoneView:(id)sender {
      if (origView == nil)
        origView = self.view;
      self.view = phoneViewController.view;
    }
    
    - (IBAction)switchToOriginalView:(id)sender {
      self.view = origView;
    }
    

提交回复
热议问题