本文所贴的代码都是主要的代码,其余内容请根据UITableView的基础知识进行自行脑补。
自定义设置cell的选中效果
cell.selectedBackgroundView = [[[UIViewalloc] initWithFrame:cell.frame]autorelease];
cell.selectedBackgroundView.backgroundColor = [UIColorlightGrayColor];
取消系统自带的线。
_tbView.separatorStyle=UITableViewCellSeparatorStyleNone;
在创建cell的时候写,取消cell的点击阴影效果
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
//解决分割线爱你不左对齐的状况
if ([_tbVirewrespondsToSelector:@selector(setSeparatorInset:)]) {
[_tbVirewsetSeparatorInset:UIEdgeInsetsZero];
}
if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[_tableView setSeparatorInset:UIEdgeInsetsMake(0,kContactsCell_bottomLine_Left,0,0)];
}
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[_tableView setLayoutMargins:UIEdgeInsetsMake(0,kContactsCell_bottomLine_Left,0,0)];
}
局部刷新
刷新某一个cell
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:row inSection:0];
[PdTabView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
刷新某一组section
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[TYSearchTabView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
// tbView.editing 默认为NO 编辑状态
tbView.editing =YES;
// 或者是下面方法设置
[tbViewsetEditing:isEditinganimated:YES];
【示范一】
//返回指定模块的编辑样式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==0) {
returnUITableViewCellEditingStyleDelete;
}
else {
returnUITableViewCellEditingStyleInsert;
}
}
//修改删除符号的文本内容
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return@"删除";
}
//提交编辑操作
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//删除操作
if (editingStyle==UITableViewCellEditingStyleDelete) {
[boyGroupremoveObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]withRowAnimation:UITableViewRowAnimationBottom];
}
//否则,添加操作
else {
[girlGroupinsertObject:@"QQ"atIndex:indexPath.row];
[tableView insertRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]withRowAnimation:UITableViewRowAnimationLeft];
}
}
【示范二】
//tbView的每一行的编辑样式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
//可以选择编辑状态为复选状态。
returnUITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//取出点击行的cell对象 编辑状态时,每点击一个cell,就把这个cell放在删除数组中。
UITableViewCell *cell=[tableViewcellForRowAtIndexPath:indexPath];
[deleteArrayaddObject:cell.textLabel.text];
}
//从选中变为不选中状态
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableViewcellForRowAtIndexPath:indexPath];
[deleteArrayremoveObject:cell.textLabel.text];
}
刷新某一个section的内容。用此可以来操作关闭和隐藏效果。
关闭就是这个section的cell count 为0
打开的话就是设置count 为几就是几
[tbViewreloadSections:[NSIndexSetindexSetWithIndex:0]withRowAnimation:UITableViewRowAnimationFade];