1
我有兩個連接在一起的UIViewControllers
。根據點擊哪個按鈕更改內容?
第一個UIViewController
有4 UIButtons
,所有這些帶我到第二個UIViewController
。
但是,內容應該根據我點擊的按鈕而改變。我怎樣才能做到這一點?
我有兩個連接在一起的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;
}
}
非常感謝! – user2164504 2013-03-13 09:04:38