gpt4 book ai didi

ios - 无法使用来自 API 的数据在 UITableView 中插入单元格

转载 作者:行者123 更新时间:2023-12-01 20:21:08 25 4
gpt4 key购买 nike

我有一种情况,我必须在我的 UITableView 中插入单元格.
我实现了这三个委托(delegate)函数,当数据在 viewDidLoad 中定义时它运行良好.

- (void)viewDidLoad {
[super viewDidLoad];
categoryData = [NSMutableArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee",@"Ham and Cheese Panini", nil];
_categoryMenuTable.dataSource = self;
_categoryMenuTable.delegate = self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:[categoryData objectAtIndex:indexPath.row]];
return cell;
}

但就我而言 categoryData来自异步 API,显然在 viewDidLoad 之后加载.

所以真正的问题是,在后一种情况下,我无法调用委托(delegate)方法。

PS我也试过
[_categoryMenuTable reloadData];

将数据设置为 categoryData 后像
-(void)setCategories:(NSMutableArray*)arr    {
categoryData = arr;
_categoryMenuTable.dataSource = self;
_categoryMenuTable.delegate = self;
[_categoryMenuTable reloadData];
}

我更想提的是我正在使用 MMDawerController
https://github.com/mutualmobile/MMDrawerController

如何从 API 获取数据到我的表中?

最佳答案

使用reloadData而不是 reload调用UITableView委托(delegate)方法

关于ios - 无法使用来自 API 的数据在 UITableView 中插入单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35706169/

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