我上下搜索过,发现了一些相似但不是我确切问题的东西。在我的详细视图控制器中,我有一个segue打开一个popover表视图控制器。在PrepareForSegue方法中,我设置了表视图的属性,如下所示:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"StateSegue"])
{
popover = [(UIStoryboardPopoverSegue *)segue popoverController];
StatePickerController *statePicker = (StatePickerController *)popover.contentViewController;
statePicker.delegate = self;
statePicker.pickerType = @"states";
}
}
我传递了委托和pickerType值。在我的表视图中,StatePickerController,在标题中我声明了这些属性:
@property (nonatomic,assign) id<StatePickerDelegate> delegate;
@property (nonatomic,strong) NSString *pickerType;
我知道这些值正在传递到我的popover控制器中,因为稍后在didSelectRowAtIndexPath中我可以引用它们并获得正确的委托和“state”,但是在viewDidLoad方法中,两者仍然是(null)。 / p>
- (void)viewDidLoad
{
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(150.0, 140.0);
self.states = [NSMutableArray array];
NSLog(@"%@",self.delegate); //returns (null)
NSLog(@"%@",self.pickerType); //returns (null)
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",self.pickerType); //corectly logs "state"
NSString *state = [_states objectAtIndex:indexPath.row];
[self.delegate stateSelected:state]; //correctly runs method on detailviewcontroller
}
在viewDidLoad方法之后是否设置了这些属性?我需要在视图加载时访问这些值,因为我需要根据detailviewcontroller传递的内容确定表中填充的数据。
答案 0 :(得分:-1)
在viewDidLoad之后调用viewWillAppear。而是使用它来检查prepareForSegue方法之后的值。