【发布时间】:2011-06-11 23:49:50
【问题描述】:
我正在创建的应用程序使用表格视图启动。我可以立即添加新信息,将信息保存到 plist,然后重新加载视图。新单元格及其数据显示在底部。但是,当我重新运行该应用程序时,它会按照我最初看到的顺序重新排序。
单元格的标题存储在名为countdowns 的变量中,描述存储在countdown_info 中。然后我使用这些变量并将它们作为字典存储在 plist 中。
这是一个每次都具有相同结果的示例。以下是我刚刚添加 4 个新单元格时的表格视图:
**[CODE 1]**
Countdown 1
Description 1
Countdown 2
Description 2
Countdown 3
Description 3
Countdown 4
Description 4
但是,当应用重新运行/重新构建时,应用会打开以下内容:
**[View After Re-Run]**
Countdown 4
Description 4
Countdown 1
Description 1
Countdown 3
Description 3
Countdown 2
Description 2
我添加的一些 NSLogs 显示文件中的表保存为 [代码 1],并且表视图上的 indexPath.row 从 0-3 增加,但由于某种原因,视图以不同的模式重新组织.
这是什么原因?谢谢!
来自 cellRowAtIndexPath 的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"] autorelease];
}
ClockworkAppDelegate *dataCenter = (ClockworkAppDelegate *)[[UIApplication sharedApplication] delegate];
cell.textLabel.text = [[dataCenter countdowns] objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [[dataCenter countdown_info] objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
【问题讨论】:
标签: objective-c ios ios4 uitableview xcode4