我正在查看桌面视图。在我的电子设备中,我得到了想要传递给下一个控制器的正确对象。
这是我的代码:
id<NavigateDelegate> strongDelegate = self.delegate;
NSDictionary * dictionary = [_dataArray objectAtIndex:indexPath.section];
NSArray * array = [dictionary objectForKey:@"data"];
POI * poi = [array objectAtIndex:indexPath.row];
NSLog(@"%@", poi);
NSLog(@"Category %@", poi.rank.name);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailsViewController * detailsController = [[DetailsViewController alloc] init];
detailsController.details = [[NSDictionary alloc] initWithObjectsAndKeys:poi.name, @"name", poi.address, @"address", poi.details, @"details", poi.title, @"title", poi.url, @"url", nil];
if ([strongDelegate respondsToSelector:@selector(navigateFromTo:to:)]) {
[strongDelegate navigateFromTo:self to:detailsController];
}
然后在我的委托接收器中,我按下控制器:
- (void) navigateFromTo:(POITableViewController *)viewController to:(UIViewController *)toController
{
[self.navigationController pushViewController:toController animated:YES];
}
但仍然是我的DetailsController他的细节NSdictionary是null。
我做错了什么?
答案 0 :(得分:0)
我发现了问题。在调用setter之前调用viewdid加载。
所以我改变了这样的init方法:
-(instancetype) initWithPoi:(NSDictionary *) poi
{
self = [super init];
if(self)
{
NSLog(@"Init DetailsViewController");
_details = poi;
[self initializeViews];
}
return self;
}
控制器从一开始就具有poi细节。