所以我知道如果有一个通过故事板设置和激活的segue,可以使用prepareForSegue
方法将数据传递到目标视图控制器。
我想知道如果使用performSegueWithIdentifier
方法,是否有办法做到这一点?似乎prepareForSegue
方法仅在使用故事板激活segue时调用,而不是使用performSegue激活。
一个特别的问题是我无法访问UIStoryboardSegue
(它不是performSegue
中的参数,因为它在prepareForSegue
中),因此无法访问目的地VC也是。
答案 0 :(得分:0)
答案在StackOverflow中。 How to pass prepareForSegue: an object
// When any of buttons are pressed, push the next view
- (IBAction)buttonPressed:(id)sender
{
[self performSegueWithIdentifier:@"MySegue" sender:sender];
}
// This will get called too before the view appears
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"]) {
// Get destination view
SecondView *vc = [segue destinationViewController];
// Get button tag number (or do whatever you need to do here, based on your object
NSInteger tagIndex = [(UIButton *)sender tag];
// Pass the information to your destination view
[vc setSelectedButton:tagIndex];
}
}