UI基础之---- UITableView 编辑

一 UITabelView 编辑

1.UItableView的编辑包括 cell 的添加和删除

2.使用场景:

1>删除一个下载好的视频,删除联系人

2>插入一条新的聊天记录

1.    UITabelView 编辑的步骤:

1>  让 tableView 处于编辑状态(使用 TableView方法)

首先需要在给 tableView添加 cell 的时候,给导航条的右边添加编辑按钮self.navigationItem.rightBarButtonItem = self.editButtonItem;

接着实现 TableView的方法:

-(void)setEditing: (BOOL)editing animated: (BOOL)animated;

2>  指定 tableView 哪些行可以编辑(TableView DataSource 方法)

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

3>  指定 tableView 编辑的样式(添加,删除)(TableView Delegate方法)

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView

editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;

4>  编辑完成(先操作数据源,再修改 UI)( TableView DataSource 方法)

-(void)tableView:(UITableView *)tableView commitEditingStyle:

(UITableViewCellEditingStyle)editingStyleforRowAtIndexPath: (NSIndexPath *)indexPath;

2.    UITableView 的移动

1>  让 tableView 处于编辑状态(TableView方法)(参见 UITableView编辑步骤一)

2>  指定 tableView哪些行可以移动(TableViewDatasource 方法)

-      (BOOL)tableView: (UITableView*)tableView canMoveRowAtIndexPath:

(NSIndexPath*)indexPath;

3>  移动完成(TableViewDatasource 方法)

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath: (NSIndexPath *)sourceIndexPathtoIndexPath: (NSIndexPath *)destinationIndexPath;

4>  检测移动过程中,实现限制区移动

-(NSIndexPath *)tableView: (UITableView *)tableViewtargetIndexPathForMoveFromRowAtIndexPath: (NSIndexPath*)sourceIndexPathtoProposedIndexPath: (NSIndexPath *)proposedDestinationIndexPath;

3.    UITableViewController控件(很牛逼的一个控件)

1>  UITableViewController 继承自 UIViewController, 自带一个 tableView

2>  self.view不是 UIView, 而是 UITableView

3>  datasource 和 delegate 默认都是 self(UITableViewController)

4>  开发中只需要建立 UITableViewController 子类

5>  UITableViewController 是封装好了各种 delegate 和 datasouce, 能提高开发速度.

4.     tableView指定为 self.view 的根视图

使用视图控制器中的加载视图的方法:

-(void)loadView{

self.tableView= [[UITableView alloc]initWithFrame:[UIScreen mainScreen]

.bounds];

self.view= self.tableView;

[self.tableViewrelease];

}

5.    设置UINavigationController导航条的外观

self.navigationController.navigationBar.barTintColor= [UIColor greenColor];

self.navigationItem.title= @”通讯录”;

6.    从**.plist 文件中获取数据

1>  获取路径

NSString*filePath = [[NSBundle mainBundle]pathForResource: @”Contacts” ofType: @”plist”];

2>  根据文件路径获取数据(存方到数组中)

self.dic = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值