0
問候語。我有一個tableView,其中的內容來自於字典。要加載的內容:mutableDictionary與UITableview一起使用:更改其可編輯屬性
//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
當我刪除它。所以修復它的最好方法是修復我的字典,請問這是真的嗎?請舉例嗎?
有關討論和示例代碼,請參閱我的書:http://www.apeth.com/iOSBook/ch21.html#_deleting_table_items – matt
嗨,matt。感謝您的回覆。我是IOS的新手。我不知道的是如何從我的字典中刪除數據源。如何將它鏈接到self.sectionKeys和self.sectionContents? – user4441082