How can I dynamically hide a button from a view?

前端 未结 12 2153
执念已碎
执念已碎 2020-12-04 21:24

I would like to dynamically hide a button in one of my views depending on a certain condition.

I tried adding some code to the view controller\'s -viewWillAppe

12条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 22:12

    If all that one is trying to hide is the back button in the navigation bar, there is an easier way:

    self.navigationItem.hidesBackButton = YES;
    

    Quote from developer documentation:

    hidesBackButton

    A Boolean value that determines whether the back button is hidden.

    @property(nonatomic, assign) BOOL hidesBackButton

    Discussion

    YES if the back button is hidden when this navigation item is the top item; otherwise, NO. The default value is NO.

    Availability

    Available in iPhone OS 2.0 and later.

提交回复
热议问题