gpt4 book ai didi

iOS - tableView reloadData 非常奇怪的问题

转载 作者:行者123 更新时间:2023-11-28 19:17:41 24 4
gpt4 key购买 nike

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

}



[cell setBackgroundColor:[UIColor lightGrayColor]];
cell.textLabel.textColor = [UIColor lightTextColor];
cell.textLabel.backgroundColor = nil;
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
cell.detailTextLabel.backgroundColor = nil;

// Get list of local notifications
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];

// Display notification info
[cell.textLabel setText:notif.alertBody];

NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"MMM dd 'at' HH:mm"];

NSString *dateString = [format stringFromDate:notif.fireDate];

NSString *textData = [[NSString alloc]initWithFormat:@"%@",dateString];

[cell.detailTextLabel setText:textData];

//[notif.fireDate description]



[self.tableView reloadData];
return cell;

}

如果我不写“[self.tableView reloadData];”,一切都绝对正常,但如果我这样做,似乎单元格在那里但没有显示(单元格分隔符根据表格 View 的单元格数量消失有)

我需要重新加载数据,这样用户就不需要退出 View 并再次加载 View 来显示更新的信息。

有什么建议吗?

最佳答案

您不需要在 cellForRowAtIndexPath 中添加 [self.tableView reloadData];,这是绝对错误的,因为调用 reloadData 会再次调用cellForRowAtIndexPath 如您所见,这会产生非常奇怪的问题

一般来说,只要您想更改 UITableView 的全部或部分内容,您通常会调用 [self.tableView reloadData];

关于iOS - tableView reloadData 非常奇怪的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11176923/

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