iOS 开发之如何编辑tableView上的cell
2015-09-15 17:23
537 查看
效果图展示:
plist 文件读取和调用
path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]stringByAppendingPathComponent:@"DetailData.plist"];
list = [[NSArray arrayWithContentsOfFile:path]mutableCopy];
1、添加导航控制器,在导航控制器上添加两个 navigationItem 编辑 和 添加
2、点击编辑的时候调用方法
1⃣️//点击一次开始编辑,点击两次结束编辑
- (void)edit
{
[myTableView setEditing:!myTableView.isEditing animated:YES];
}
2⃣️编辑tableView
上的cell
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//
判断编辑中的样式 是否是
删除的样式
if (editingStyle == UITableViewCellEditingStyleDelete ) {
// 1、删除数据
// 2、更新视图
//
移除数组里面的数据
[list removeObjectAtIndex:indexPath.row];
//
把移除后的数据 同步到 plist
里面
BOOL success = [list writeToFile:path atomically:YES];
//
如果数据同步成功 ,就删除数据里面的cell
if (success) {
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
}
3⃣️、cell之间的移动
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
//
如果移动的不是同一个位置 才进行操作
if (sourceIndexPath.row != destinationIndexPath.row) {
// 1、
保存
需要移动的数据
NSDictionary *info = list[sourceIndexPath.row];
// 2、移除
需要移动的数据
[list removeObjectAtIndex:sourceIndexPath.row];
// 3、插入数据
// destinationIndexPath
可以得到 咱们要移动的位置
[list insertObject:info atIndex:destinationIndexPath.row];
// 4、同步数据到plist
[list writeToFile:path atomically:YES];
}
}
plist 文件读取和调用
path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]stringByAppendingPathComponent:@"DetailData.plist"];
list = [[NSArray arrayWithContentsOfFile:path]mutableCopy];
1、添加导航控制器,在导航控制器上添加两个 navigationItem 编辑 和 添加
2、点击编辑的时候调用方法
1⃣️//点击一次开始编辑,点击两次结束编辑
- (void)edit
{
[myTableView setEditing:!myTableView.isEditing animated:YES];
}
2⃣️编辑tableView
上的cell
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//
判断编辑中的样式 是否是
删除的样式
if (editingStyle == UITableViewCellEditingStyleDelete ) {
// 1、删除数据
// 2、更新视图
//
移除数组里面的数据
[list removeObjectAtIndex:indexPath.row];
//
把移除后的数据 同步到 plist
里面
BOOL success = [list writeToFile:path atomically:YES];
//
如果数据同步成功 ,就删除数据里面的cell
if (success) {
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
}
3⃣️、cell之间的移动
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
//
如果移动的不是同一个位置 才进行操作
if (sourceIndexPath.row != destinationIndexPath.row) {
// 1、
保存
需要移动的数据
NSDictionary *info = list[sourceIndexPath.row];
// 2、移除
需要移动的数据
[list removeObjectAtIndex:sourceIndexPath.row];
// 3、插入数据
// destinationIndexPath
可以得到 咱们要移动的位置
[list insertObject:info atIndex:destinationIndexPath.row];
// 4、同步数据到plist
[list writeToFile:path atomically:YES];
}
}
相关文章推荐
- [原]IOS 7.1 以上企业及开发解决方案
- 开始iOS 7中自动布局教程(一)
- CocoaPods安装和使用
- ios utf8编码和解码
- iOS GCD使用指南
- 关于自己学习ios oc的学习笔记
- IOS开发中图片资源使用png还是jpg格式
- iOS 图片处理(截图,图片叠加(添加水印))
- iOS开发日记19-7.0之后的截屏方法
- Mac环境下svn的使用
- ios制作空白视频
- ios 指南针
- ios 开发 icon图标设置
- iOS开发之 分段选择控件 开关 滑杆
- iOS 调取本地相册/相机,剪裁图片进行头像上传
- iOS获取plist文件属性值的方法
- iOS开发之 手势
- iOS 不要使用tag传递TableViewCell的indexPath值
- ios 定位 航向检测
- SVProgressHUD–比MBProgressHUD更好用的 iOS进度提示组件