思路:
1、根据数组的索引和indexpath的row联系起来
2、现在didSelectedRowAtIndexPath中弹出UIAlertView和相关信息,然后在UIAlertView协议的clickedButtonAtIndex中将alert的数据传递给数据源,然后通过刷新,即可形成信息的改。
3、右侧的箭头:cell setAccessoryType:
4、改完数据以后要更新,有全部更新和更具选中行部分更新
1、1选中行返回选中行的indexpath tableview indexPathForSelectedRow
开发中常见的隐藏问题:
如果写了cell代码优化,并且需求是每行根据实际的数目来显示,那么当超出屏幕范围的时候,从缓冲池中取出单元行时,会显示出一整行的内容,却不是实际的个数。
所以要写判断
如若需要将状态栏隐藏,最好使用代码实现
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
- (BOOL)preferstatusBarHidden
{
return YES;
}
UIAlertView中的按钮和文本行可以利用index来指向
表格优化: 数字11的含义
单元格内容方法
1、标示符统一,使用static的目的可以保证表格标示符永远只有一个
static NSString* cellIdentifier = @"myCell";
2、首先在缓冲池中找名为“myCell”的单元格对象
UITableViewCell* cell = [tableview dequeueReusableCellWithIdentifier:cellIdentifier];
3、如果没有找到,实例化一个新的cell
if (cell == nil)
{
cell = [[UITableCell alloc] initWithStyle:UITableViewCellStyleDefautl reuseIdentifier:cellIdentifier];
}
Navigation Controller和TableView相结合
在级联中,利用上下级视图,在prepareForSegue中,获取下级的viewController然后利用set方法传递数据给下级的viewController。再在下级视图中显示
代码块功能提高复用性
//TODO:
<#xxxx#>代码table显示
表格移动行的方法,只要实现了- (void)tableView:moveRowAtIndexPaht:toIndexPath即可
实际是先删除了原来位置的数据,进行了记录,然后在目标位置再还原
其实的目标位置之所以不用加一,是因为其实在删除原来位置的同时,总数已经减1了,插入后的总数其实还是没有变化
static NSString *CellIdentifier = @"bookCell";
// 2. 从缓存池查找是否有可用的表格行对象
BookCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// 3. 如果没有找到可重用单元格对象,实例化新的单元格
if (cell == nil) {
NSLog(@"实例化单元格对象");
cell = [[BookCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
IOS6之后:
static NSString *CellIdentifier = @"bookCell";
// 2. 从缓存池查找是否有可用的表格行对象
BookCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
前提已经在storyboard中建立了cell或者注册了xib文件,使用了自定义单元格
注意xib中的identifire
// 注意:以下几句注册XIB的代码,一定要在viewDidLoad中!
// 注册XIB文件
UINib *nib = [UINib nibWithNibName:@"BookCell" bundle:[NSBundle mainBundle]];
// 获得根视图,并且转换成TableView
UITableView *tableView = (UITableView *)self.view;
// 为tableView注册xib
[tableView registerNib:nib forCellReuseIdentifier:@"bookCell"];
重点:表格优化,根据系统的版本。
//新增表格数据
[tableViewinsertRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationTop];
//删除表格数据
[tableViewdeleteRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationRight];
//局部刷新指定的行
[tableViewreloadRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationMiddle];
//刷新全部表格数据,如果能够准确确定被修改的数据行,就不要用此方法
[tableViewreloadData];不支持动画,仅在我们不知道哪个位置的数据被改了才使用
- (void)tableView:commitEditingStyle:forRowAtIndexPath:
- (UITableViewCellEditingStyle)tableView:editingStyleForRowAtIndexPath:
UITextView 多行文本。支持编辑,数据检测
2、;