IOS控件之UITableView

动画的开始和结束
beginUpdates
endUpdates
因为,如果我们的UITableView是分组的时候,我们如果删除某个分组的最后一条记录时,相应的分组也将被删除。所以,必须保证UITableView的分组,和cell同时被删除。
所以,就需要使用beginUpdates方法和endUpdates方法,将要做的删除操作“包”起来!
 
 一般在UITableView执行:删除行,插入行,删除分组,插入分组时,使用!用来协调UITableView的动画效果。
  

插入指定的行,

在执行该方法时,会对数据源进行访问(分组数据和行数据),并更新可见行。所以,在调用该方法前,应该先更新数据源

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation


插入分组到制定位置

- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation

插入一个特定的分组。如果,指定的位置上已经存在了分组,那么原来的分组向后移动一个位置。


删除制定位置的分组

- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation

删除一个制定位置的分组,其后面的分组向前移动一个位置。


移动分组 和 行

- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection

移动原来的分组从一个位置移动到一个新的位置。如果,新位置上若存在某个分组,那这某个分组将会向上(下)移动到临近一个位置。该方法,没有动画参数。会直接移动。并且一次只能移动一个分组。

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

移动行


单元格操作

提交

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

能否编辑

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

必须开启 tableview.editing 这个属性为真可以编辑.

这个属性定义cell的风格

tableview.accessoryType 

typedef enum : NSInteger {    

UITableViewCellAccessoryNone,     //正常风格

UITableViewCellAccessoryDisclosureIndicator,    //最右边有一小箭头

UITableViewCellAccessoryDetailDisclosureButton,  //最右边有一按钮式的小箭头

UITableViewCellAccessoryCheckmark,    //右边有一对勾

UITableViewCellAccessoryDetailButton //按钮

} UITableViewCellAccessoryType; 


这个属性是UIView的属性继承过来的

tableView.autoresizingMask

UIViewAutoresizingNone                 = 0  //控件相对于父视图坐标值不变;
UIViewAutoresizingFlexibleLeftMargin   = 1 << 0 //到屏幕左边的距离随着父视图的宽度按比例改变;
UIViewAutoresizingFlexibleWidth        = 1 << 1  //控件的宽度随着父视图的宽度按比例改变,例如:label宽度为100,屏幕的宽度为320。当屏幕宽度为480时,label宽度变为100*480/320
UIViewAutoresizingFlexibleRightMargin  = 1 << 2 //到屏幕右边的距离随着父视图的宽度按比例改变;
UIViewAutoresizingFlexibleTopMargin    = 1 << 3 //到屏幕上边的距离随着父视图的宽度按比例改变;
UIViewAutoresizingFlexibleHeight       = 1 << 4 //UIViewAutoresizingFlexibleWidth相同
UIViewAutoresizingFlexibleBottomMargin = 1 << 5 //到屏幕底边的距离随着父视图的宽度按比例改变;


重新加载指定行
UITableView的- (void)reloadRowsAtIndexPaths:( NSArray  *) indexPaths  withRowAnimation:( UITableViewRowAnimation ) animation
这一方法会重新加载所指定indexPaths中的UITableViewCell实例,因为重新加载cell所以会请求这个UITableView实例的data source来获取新的cell;这个表会用动画效果让新的cell进入,并让旧的cell退出。 会调用UITableViewDataSource协议中的所有方法来更新数据源,其中调用 ( UITableViewCell  *)tableView:( UITableView  *)tableView cellForRowAtIndexPath:( NSIndexPath  *)indexPath  只会调用所需更新的行数,来获取新的cell,

注意:此时该cell的- (void)setSelected:(BOOL)selected animated:(BOOL)animated将被调用,所设置的selected为NO;




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值