2 UITableViews in one UIView

后端 未结 5 1375
一生所求
一生所求 2020-12-02 23:23

I have a UIView that will need to display two UITableViews, but they are never shown together, by using a SegementedBar you can toggle one or the o

5条回答
  •  不知归路
    2020-12-02 23:53

    Use separate UITableViewControllers and swap the views. It's less code, less complexity and it's the way Apple does it with the TabBar.

    As for code complexity, there really isn't any. You simply do the following to switch views when the UISegmentedControl's value has changed:

    UIView *previousSuperview = myViewController1.view.superview;
    myViewController2.view.frame = myViewController1.view.frame;
    [myViewController1.view removeFromSuperview];
    [previousSuperview addSubview:myViewController2.view];
    

    Alternatively, you could set the corresponding view's hidden property.

提交回复
热议问题