0

如何通过单击另一个 UIViewController 中的 UIButton 来显示 Button?单击 SecondViewController 中的按钮时,我想在 FirstViewController 中添加一个按钮...原谅我的糟糕问题。

4

1 回答 1

1

简短回答:在您的第一个 VC 界面中设置一个布尔属性,并在第二个 VC 中按下另一个按钮时访问它。使用布尔标志在第一个 VC 中添加(或显示/隐藏)按钮。

长答案:如果你想“添加”一个按钮或者你想“显示”一个已经存在的隐藏按钮,策略会有点不同。假设您要“添加”一个按钮:

  1. 在您的 FirstViewController 的界面中,您需要:

    @property BOOL firstButtonShouldShow;

    @property (strong, nonatomic) IBOutlet UIButton* firstButton;

    //并确保将插座连接到按钮

  2. 在 FirstViewController.m 你需要:

    -(无效)viewDidLoad {

    if (firstButtonShouldShow) [firstButton setHidden:NO];

    否则 [firstButton setHidden:YES];

    {

  3. 现在在您的 SecondViewController.m 中:

    -(void)prepareForSegue ... {

    FirstViewController* firstVC = segue.destinationViewController;
    
    firstVC.firstButtonShouldShow = YES;
    

    }

于 2014-04-28T21:45:12.387 回答