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.
}
}
//插入数据在第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.
}
}
相关文章推荐
- oracle基本查询语句(一)用户相关语句
- uva 11195 Another queen (用状态压缩解决N后问题)
- 如何利用FineBI做财务分析
- SQL介绍及在ubuntu下的安装
- Vim学习
- SYN011型 B码时统
- OAF中的面包屑(breadcrumbs)始无法显示(转)
- Python学习笔记——数字
- 蓝桥杯 历届试题 小朋友排队
- 追求Masonry
- php中使用$_REQUEST需要注意的一个问题
- AIX调整swap大小
- 多文件,多头文件时gcc与makefile的编写经验
- rel_exp - IS BOUND
- JVM:编译加载与自定义类加载器
- this指针
- ArrayList、LinkedList和Vector 的区别
- 为什么编程语言以及数据库要从1970年1月1日开始计算时间【转】
- C++标准库之stack(各函数及其使用全)
- CUBRID学习笔记 5 错误码