我有一個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