我有两个链接在一起的UIViewControllers
。
第一个UIViewController
有4个UIButtons
,所有这些都将我带到第二个UIViewController
。
但是,内容应根据我单击的按钮而变化。我怎样才能做到这一点?
最佳答案
给每个按钮一个唯一的标记,并使用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;
}
}
关于ios - 根据单击的按钮更改内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15380543/