gpt4 book ai didi

iOS TableViewController 不显示

转载 作者:行者123 更新时间:2023-11-28 19:06:21 25 4
gpt4 key购买 nike

我制作了一个带有 TableView 的 UIViewController,它显示来自服务器的内容我的代码是这样的:

- (void) viewDidLoad{
[super viewDidLoad];
NSUserDefaults *userDefaults = [UserDefaults instance];
[Async activitiesForPersonId:[userDefaults objectForKey:USERDEFAULTS_PERSONID]
unionId:[userDefaults objectForKey:USERDEFAULTS_UNIONID]
callback:^(NSArray *activities){
if(activities && [activities count] != 0){
NSLog(@"%hhd",[NSThread isMainThread]); //1
NSLog(@"%i", [activities count]); //16
self.activities = activities;
}else{
NSLog(@"What the ...."); //Doesn't get printed
}
}];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.activities count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"CalendarActivity";
CalendarCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
return cell;
}

怎么屏幕上没有任何显示。当我将 [self.activities count] 更改为例如硬编码 5 时,它会显示 5 个单元格。所以我想我已经通过 IB 正确设置了数据源。此外,数据来自另一个线程,但在主线程上返回它,所以这可能也不是问题。

最佳答案

您实际上并未在单元格中设置任何内容。例如:

- (void)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
// Set up cell stuff
cell.textLabel.text = @"Title For Cell";

return cell;
}

编辑:

一旦数据准备好显示,您可能需要重新加载 tableView,[tableView reloadData]; 应该为您完成此操作。

关于iOS TableViewController 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20099125/

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