问候语。我有一个tableView,其内容来自字典。要加载内容:
//For the table view content
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
}
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
NSArray *contents = [[self sectionContents] objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];
cell.textLabel.text=contentForThisRow;
//cell.textLabel.text=[self.msgCourse objectAtIndex:indexPath.row];
return cell;
}
我想让行可编辑,比如用户可以删除一些行:
//Below are for editting
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
我知道删除它时必须返回错误content not matching with the dictionary
。所以修复它的最好方法是修复我的字典,这是真的吗?有什么例子吗?
答案 0 :(得分:1)
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
问题是你没有做评论所说的。您没有从数据源(self.sectionKeys
和self.sectionContents
)删除该行。您必须在之前从表中删除行。