gpt4 book ai didi

ios - 无法使用新数据更新单元格为 (cell!=nil)

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:36:43 25 4
gpt4 key购买 nike

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell addButtons:buttonsArray];
}

[cell renderCell:[self.dataArray objectAtIndex:indexPath.row]];
return cell;
}

viewDidAppear buttonArray 已更改,因此我想使用新的 buttonArray 更新我的单元格。我正在使用 [tableView reloadData] 但由于 (cell != nil) 我无法更新

最佳答案

我的建议是,如果单元格为 nil,您可以添加按钮,并在 if 条件之外更改按钮的数据

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell addButtons:buttonsArray]; // add the buttons
}
[cell updateButtonData:dataArray]; // update the data on the button
[cell renderCell:[self.dataArray objectAtIndex:indexPath.row]];
return cell;
}

关于ios - 无法使用新数据更新单元格为 (cell!=nil),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35363163/

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