1

我有两个UIViewControllers链接在一起。

第一个UIViewController有 4 个UIButtons,所有这些都带我到第二个UIViewController

但是,内容应该根据我点击的按钮而改变。我怎样才能做到这一点?

4

1 回答 1

5

给每个按钮一个唯一的标签,并使用prepareForSegue:sender:您可以检查单击的按钮标签的方法,然后相应地更改您的内容。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   UIButton *buttonSender = (UIButton *)sender;
   NSLog(@"Tag of the button tag selected = %d", buttonSender.tag);

   switch (buttonSender.tag) {
        case 1:
            // Content if button 1 was clicked.
            break;
        case 2:
            // Content if button 2 was clicked.
            break;
        case 3:
            // Content if button 3 was clicked.
            break; 
        case 4:
            // Content if button 4 was clicked.
            break;   
        default:
            break; 
   }
}
于 2013-03-13T08:50:21.353 回答