您的位置:首页 > 其它

TableView 插入表格和删除表格

2016-03-16 13:50 253 查看
@property NSMutableArray *objects;

//插入数据在第0行

- (void)insertNewObject:(id)sender {

if (!self.objects) {

self.objects = [[NSMutableArray
alloc] init];

}

[self.objects
insertObject:[NSDate
date] atIndex:0];

NSIndexPath *indexPath = [NSIndexPath
indexPathForRow:0
inSection:0];

[self.tableView
insertRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];

}

//设置可编辑状态

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

// Return NO if you do not want the specified item to be editable.

return
YES;

}

//删除所编辑的单元格

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath
*)indexPath {

if (editingStyle ==
UITableViewCellEditingStyleDelete) {

[self.objects
removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];

} else
if (editingStyle ==
UITableViewCellEditingStyleInsert) {

// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: