允许对cell进行编辑和拖动

本文介绍了如何在iOS应用中实现UITableView的编辑功能,包括删除单元格、调整单元格内控件的位置以及允许用户拖动单元格来重新排序。通过具体的代码示例展示了如何开启编辑模式、响应单元格选择事件及实现单元格的移动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

允许对cell进行编辑(删除)

 

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

{

//打开编辑

return YES;

}

 

- (void)setEditing:(BOOL)eanimated:(BOOL)ani

{

[super setEditing:eanimated:ani];

[mSpecialTableViewsetEditing:e animated:ani];//tableView设置

 

if (e)self.editButtonItem.title =_(@"done");

elseself.editButtonItem.title =_(@"edit");

}

//tableView 中cell选中事件

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath

{

NSInteger specialIndex = [[TQDownListshareInstance]getCurSepcailIndex:indexPath.row];

NSString *strKey = [[TQDownListshareInstance]getCurRowIndex:specialIndex];

 

TQDownViewSecondPage *taskPage =[[TQDownViewSecondPage alloc]init];

[taskPage setSpecialKey:strKey];

[self.navigationControllerpushViewController:taskPageanimated:YES];

[taskPage release];

}

//编辑tableView 时调整cell view里的控件位置

 

- (void)layoutSubviews

{

#define REDUCE_LEN 59

 

int tag = 25;

if(self.editing) 

{

//编辑时的位置

} else 

{

//默认位置 

 

}

[superlayoutSubviews];

}

四、允许cell之间的拖动

 

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

{

//允许移动

return YES;

//return NO;

}

- (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath

{

//交换数据

 

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值