【发布时间】:2012-06-24 11:05:50
【问题描述】:
- (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];”,一切都会变得绝对正常,但如果我这样做,似乎单元格在那里但它没有被显示(单元格分隔符根据表格视图的单元格数消失有)
我需要重新加载数据,这样用户就不需要离开视图并再次加载视图来显示更新的信息。
有什么建议吗?
【问题讨论】:
-
正如 Omar 所说,这是重新加载数据的错误位置。做一个
newItem方法,然后在那里做一个[tableView reloadData]。或者当您删除/清除项目时。 -
你能举个例子吗?
-
reloadData仅用于告诉表视图应从您的控制器重新加载数据(即,将调用您在上面发布的一些委托方法)。如果您还没有,请查看this。
标签: ios xcode tableview reloaddata