How do I show and/or hide a subview using swift

后端 未结 4 1564
夕颜
夕颜 2021-02-01 15:52

So I\'ve created a ViewControl in my storyboard that has 3 subviews. Each one represents a different view I want to show depending on which table row was selected on the previou

4条回答
  •  名媛妹妹
    2021-02-01 16:24

    If you have tags for each view you can hide and display them using:

    Objective C

    For Hiding:

    [[self.view viewWithTag:1] setHidden:YES];
    

    Showing:

    [[self.view viewWithTag:1] setHidden:NO];
    

    In Swift:

    Hiding:

    self.view.viewWithTag(1)?.isHidden = true
    

    Showing:

    self.view.viewWithTag(1)?.isHidden = false
    

    NOTE: Replace 1 with your tag value.

提交回复
热议问题