gpt4 book ai didi

ios - 表格单元格未显示

转载 作者:行者123 更新时间:2023-11-28 22:12:14 25 4
gpt4 key购买 nike

我正在开始 iOS 编程,但遇到了障碍。我有一个登录 View Controller ,它使用以下代码将控件(在检查用户身份验证等之后)重定向到选项卡 Controller (主屏幕):

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *viewController = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"homescreen"];
[self presentViewController:viewController animated:YES completion:nil];

主屏幕中的第一个 View Controller 是一个导航 Controller ,它通向订阅 View Controller (一个 TableView Controller )。从 app delegate.m,我试图发送一个值数组 (chefs),该表可以使用以下代码来填充自身:

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 数组“chefs”已正确填充,并且在 Storyboard中,表格单元格值(UILabel 等)已正确连接到内容 View 中的对应值。作为检查,我 NSLogged 订阅 View Controller 中的 [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。我怀疑我没有正确广播数组。

编辑:我删除了登录 View Controller 并将选项卡栏 Controller 设为 Root View Controller 。然后使用了这段代码:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [tabBarController viewControllers][0];
SubscriptionViewController *controller = [navigationController viewControllers][0];
controller.chefs = _chefs;

现在我可以看到正确的单元格了。我不确定我将控件从登录 View 重定向到选项卡栏 Controller 的方式是否正确,或者我使用 Storyboard ID 广播数组的方式是否正确。有什么指点吗?

最佳答案

听起来你的数组没有正确初始化,当你像这样分配它时:

controller.chefs = _chefs;

在使用 _chefs 做任何事情之前,确保它在某处被初始化:

_chefs = [[NSArray alloc]init];

关于ios - 表格单元格未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22596431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com