星空网 > 软件开发 > 操作系统

UITableView 表视图编辑

UITableViewController(表视图控制器)继承自UIViewController,自带一个tableView
self.view不是UIView而是UITableView
datasource和delegate你默认都是self(UITableViewController)
开发过程中只需建立UITableViewController子类
 
tableView编辑
 
tableView编辑:cell的添加、删除
使用的场景:删除一个下载好的视频,删除联系人。
插入一条新的聊天记录等
 
UITableView 表视图编辑images/loading.gif' data-original="http://images.cnitblog.com/blog2015/741774/201505/041346261733940.png" />
编辑的步骤
 
1、self让tableView处于编辑状态
UITableView 表视图编辑
 

    //editButtonItem对应的相应方法内部会根据点击按钮的状态通过setEditing:animtated:方法来控制表视图是否进入编辑状态
     self.navigationItem.rightBarButtonItem = self.editButtonItem;
2、指定tableView那些行可以编辑
UITableView 表视图编辑

 

UITableView 表视图编辑

 
3、指定tableView编辑样式(添加、删除)
UITableView 表视图编辑


UITableView 表视图编辑
 
4、编辑完成(先操作数据源,在修改UI)
UITableView 表视图编辑
// Override to support editing the table view.- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {  if (editingStyle == UITableViewCellEditingStyleDelete) {    // Delete the row from the data source//    1、应当先删除对应行的数据//    2、再将对应行的单元格从表视图中删除    [self.datasource removeObjectAtIndex:indexPath.row];    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];  } 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//    1、现在数组中插入对应的对象//    2、创建对应对象的indexPath//    3、根据indexPath在表视图中的位置插入对应行    [self.datasource addObject:@"新插入的数据"];    NSIndexPath *insertPath = [NSIndexPath indexPathForRow:self.datasource.count - 1 inSection:0];    [tableView insertRowsAtIndexPaths:@[insertPath] withRowAnimation:UITableViewRowAnimationMiddle];  }  }

当表格被拖拽后会相应此方法,

 

 UITableView 表视图编辑

 

当表格处于编辑状态时,可以通过以下方法设置相应的表格是否与许被编辑

 

UITableView 表视图编辑


 



原标题:UITableView 表视图编辑

关键词:ie

ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

产品推广(ProductBoost)添加预算常见问题解答!:https://www.ikjzd.com/articles/96153
碧梨BillIe Eilish || 带你走进这位最强00后的网红世界:https://www.ikjzd.com/articles/96154
买家迟迟不下单?教你几句英文搞定“TA”!:https://www.ikjzd.com/articles/96155
英美卖家都是怎么赚钱的?:https://www.ikjzd.com/articles/96156
产品推广(ProductBoost)活动状态和活动操作指南!:https://www.ikjzd.com/articles/96157
外贸新人,这几点你必须要注意!:https://www.ikjzd.com/articles/96158
精简版TikTok在法国、西班牙上线,引发欧盟风险质疑:https://www.kjdsnews.com/a/1842206.html
精简版TikTok在法国、西班牙上线,引发欧盟风险质疑:https://www.goluckyvip.com/news/219224.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流