一 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];