我尝试使用以下代码。它工作正常。但我无法弄清楚如何实现一些目标。
当我在同一行点击“删除”按钮而不是删除控件时,如何添加插入控件?
如果我在“第1节”和“第2节”之间移动了“第3节”,如何更新所有这三个部分并删除它们?
到目前为止,我已经使用以下代码获得了以下输出。
-(void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Handle things when deletion control clicked!
//[sectionArray removeObjectAtIndex:indexPath.row];
//[self.tableView reloadData];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
//Handle things when insertion control clicked!
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
// No editing style if not editing or the index path is nil.
if (isEditMode == NO || !indexPath) return UITableViewCellEditingStyleNone;
if (indexPath.row == 1){
return UITableViewCellEditingStyleDelete;
}else if (indexPath.row == 2){
return UITableViewCellEditingStyleInsert;
}else if (indexPath.row == 3){
return UITableViewCellEditingStyleInsert;
}else {
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath {
NSString *item = [sectionArray objectAtIndex:fromIndexPath.row];
[sectionArray removeObject:item];
[sectionArray insertObject:item atIndex:toIndexPath.row];
NSLog(@"%@", sectionArray);
}
答案 0 :(得分:0)
第二个问题的解决方案是,您需要在执行删除和插入操作后刷新表格视图
答案 1 :(得分:0)
我希望此链接对您有所帮助。
http://code4app.net/ios/UITableView-actions/50bf05986803fa8e5c000001
http://www.appcoda.com/model-view-controller-delete-table-row-from-uitableview/
对于UI问题的任何时候,您也可以从这一侧获得演示应用程序。