我有一个表控制器,我在其中使用didSelectRowAtIndexPath从推送的单元格导航到另一个视图。在其中我初始化新的视图控制器并在其中推送一些数据。之后我做pushViewController。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
ServicesModel *service = [services objectAtIndex:indexPath.row];
ServiceViewController *serviceViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ServiceView"];
serviceViewController.serviceModel = service;
NSLog(@"Set model %@", service.title);
// Pass the selected object to the new view controller.
[self.serviceController pushViewController:serviceViewController animated:YES];
}
在我的ServiceViewController中,我有一个标签serviceTitle和ServiceModel属性用于选定的服务
@property (weak, nonatomic) IBOutlet UILabel *serviceTitle;
@property (strong, nonatomic) ServiceModel *serviceModel;
使用viewDidLoad我正在尝试更改标签的文本
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"viewDidLoad %@", self.serviceModel.title);
self.serviceTitle.text = self.serviceModel.title;
}
我也在尝试访问viewDidAppear中的模型
- (void) viewDidAppear:(BOOL)animated
{
NSLog(@"viewDidAppear %@", self.serviceModel.title);
}
但是当视图打开时,标签是空的。为什么?我究竟做错了什么?最奇怪的是日志:
(-[ServiceViewController viewDidLoad]) (ServiceViewController.m:43) viewDidLoad (null)
(-[ServicesTableViewController tableView:didSelectRowAtIndexPath:]) (ServicesTableViewController.m:127) Set model Google.com
(-[ServiceViewController viewDidAppear:]) (ServiceViewController.m:36) viewDidAppear (null)
它显示viewDidLoad在我分配模型属性之前触发。并且在viewDidAppear模型属性中仍然为空。怎么可能?