在项目中UITableCell经常涉及到删除cell的功能,如果设置失当就会造成崩溃后果,这里的设置主要是指cell的数量,以及数据源的变动,其牵涉到的代理主要要有:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// NSLog(@"section number::%tu",[self.indexArr count]);
return [self.indexArr count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
}另外需要特别注意的是删除cell需要分两种情况,第一种为纯粹删除cell,如下图:
调用这个接口:
[tableView deleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
另一种是连带section也要删除,如下图:
则一定要调用这个接口:
[tableView deleteSections:[NSIndexSetindexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationLeft];