我有一个ViewController,它在Interface Builder中创建了几个按钮。第一个按钮将显示在IB中链接的弹出式窗口,它链接到UINavigationController并在其下有一个类别为PopupViewController
的TableView。使用弹出窗口在prepareForSegue中设置属性
第二个按钮,我有一个动作设置为goToCategory
和上点击的时候,我想设置在PopupViewController
ViewController.m
//go to category
-(IBAction)goToCategory:(id)sender{
NSLog(@"GO TO CAT");
//PopupViewController *popupVC = [self.storyboard instantiateViewControllerWithIdentifier:@"popoverVC"];
//popupVC.currentLevel = 1;
[self performSegueWithIdentifier:@"popoverSegue" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(@"seg1");
if ([[segue identifier] isEqualToString:@"popoverSegue"]){
//PopupViewController *popupVC = (PopupViewController *)[[segue destinationViewController] visibleViewController];
//PopupViewController *popupVC = [segue destinationViewController];
PopupViewController *popupVC=[[[segue destinationViewController]viewControllers]objectAtIndex:0];
popupVC.test = @"just a test";
NSLog(@"seg2");
}
}
PopupViewController.h
@property (nonatomic, strong) NSString *test;
PopupViewController.m
@synthesize test;
-(void)viewDidLoad{
NSLog(@"test: %@", test); //returns test: (null)
}
属性我发现了很多SO答案,因此一些在我的prepareForSegue中注释掉的线条。但是这些都没有设定值test
。 PopupViewController *popupVC = [segue destinationViewController];
由于引用了UINavigationController而引发错误,所以我不能直接使用它,即使这似乎是在我见过的很多答案中做到的。但是不管我尝试用哪种方式做,输出总是空的?
UPDATE:
PopupViewController *popupVC = (PopupViewController *)[[segue destinationViewController] visibleViewController];
和PopupViewController *popupVC=[[[segue destinationViewController]viewControllers]objectAtIndex:0];
从我prepareForSegue
在6.1模拟器都工作上面。我的iPad的iOS是5.1.1,它不工作。我需要为iOS 5做些什么不同吗?
嗯,如果你想访问你的酥料饼,这应该工作:[(UIStoryboardPopoverSegue *)Segue公司popoverController] – Leonardo 2013-02-19 10:28:30