我刚开始进行iOS编程,但遇到了一个障碍。我有一个登录视图控制器,它使用以下代码将控件(在检查用户身份验证等之后)重定向到选项卡控制器(主屏幕):
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UITabBarController *viewController = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"homescreen"];
    [self presentViewController:viewController animated:YES completion:nil];主屏幕中的第一个视图控制器是指向Subscription view controller (表视图控制器)的导航控制器。在应用委托.m中,我尝试发送一个值数组(Chef),该表可以使用以下代码填充其自身:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabBarController = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"homescreen"];
UINavigationController *navigationController = [tabBarController viewControllers][0];
SubscriptionViewController *controller = [navigationController viewControllers][0];
controller.chefs = _chefs;但是,该表显示为空。已经适当地填充了NSMutable数组“chef”,并且在情节提要中,表格单元格值(UILabels等)已正确连接到内容视图中的对应值。作为检查,我在订阅视图控制器中NSLogged了self.chefs count值:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSLog(@"%d",[self.chefs count]);
return [self.chefs count];
}但是,这将返回0。我怀疑,我没有正确地广播阵列。
编辑:我删除了登录视图控制器,并使标签栏控制器成为根视图控制器。然后使用这段代码:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [tabBarController viewControllers][0];
SubscriptionViewController *controller = [navigationController viewControllers][0];
controller.chefs = _chefs;现在我可以看到正确的单元格了。我不确定我将控件从登录视图重定向到选项卡栏控制器的方式是否正确,或者我使用情节提要ID广播数组的方式是否正确。有什么建议吗?
发布于 2014-03-24 04:22:05
当你像这样分配数组时,听起来你的数组没有被正确地初始化:
controller.chefs = _chefs;在对_chefs执行任何操作之前,请确保它已在某个地方初始化:
_chefs = [[NSArray alloc]init];发布于 2014-03-24 05:12:59
也许_chefs被释放了?尝试像这样赋值
controller.chefs = [NSArray arrayWithArray:_chefs];还要确保在赋值之后重新加载控制器中的表。也许可以像这样在控制器中实现setter:
-(void)setChefs:(NSArray*)chefs
{
    _chefs = chefs;
    [self.tableview reloadData];
}https://stackoverflow.com/questions/22596431
复制相似问题