Iphone 切换UITableViewCell时无法看到删除按钮
我正在尝试从Iphone 切换UITableViewCell时无法看到删除按钮,iphone,objective-c,cocoa-touch,uitableview,Iphone,Objective C,Cocoa Touch,Uitableview,我正在尝试从UITableView中删除UITableViewCell 已将UITableViewDelegate,UITableViewDataSource实现到我的UIViewController 还要实现需要为上述委托定义的所有方法,如 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath; - (void)tableView:(UITableView *)tabl
UITableView
中删除UITableViewCell
已将UITableViewDelegate
,UITableViewDataSource
实现到我的UIViewController
还要实现需要为上述委托定义的所有方法,如
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
将UITableView也设置为编辑模式
[tableView setEditing:YES animated:YES];
当我点击“删除”按钮将tableView设置为编辑模式时,我可以看到“-”红色按钮,但当我点击该按钮时,无法看到“删除”按钮,也无法看到在单元格上滑动的时间
我浏览了stackoverflow的所有帖子,但没有找到解决方案
提前感谢。以下是我用来完成此任务的方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
[myArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
我认为您缺少了tableView:editingstyleforrowatinexpath方法。尝试将下面的代码添加到您的实现中
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
请移开
[tableView setEditing:YES animated:YES];
用这个方法
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
并对“删除”按钮执行操作
-(void)tableView:(UITableView*)tableView提交方式:
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//add action on delete button
}
此方法用于在滑动选定的TableViewCell时显示“删除”按钮
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
}
此方法将在滑动TableViewCell时点击delete按钮执行操作
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
}
此方法将在删除表视图中的行后更新表视图
- (void)tableView:(UITableView *)tableView
didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
}
我已经实现了上面的方法。。。如下所示,如果(editingStyle==UITableViewCellEditingStyleDelete){//从数据源[self-DeleteRowstIndeXPath:indexPath]中删除行;//用于删除行[tableView DeleteRowstIndeXPaths:[NSArray arrayWithObject:indexPath]和RowAnimation:UITableViewRowAnimationTop]的方法;但你从来没有真正从数组中删除过对象?至少看起来是这样。我给你的代码在我正在开发的应用程序中运行得非常好,所以请按我使用的方式尝试。也许它对你有用,但对于执行此函数“Delete”按钮应该出现。一旦我点击这个按钮,这个函数就会被调用并执行删除。但我的问题是我看不到“删除”按钮。