如何解决如何在UITableViewCell中实现简单的删除带有红色的减号按钮
|| 我正在从表格视图中删除单元格,并实现了滑动删除功能,下面是我正在使用的以下代码:#pragma mark -
#pragma mark Table View Data Source Methods
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[addTagTableView setEditing:editing animated:YES];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
//Updating the data-model array and deleting the row
- (void)tableView:(UITableView *)tv commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// If row is deleted,remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.tagsArray removeObjectAtIndex:indexPath.row];
[self.addTagTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
这允许我实现滑动删除,但是我想要简单的减红色按钮删除,如何实现呢?
解决方法
您可以放置UIButton并将其连接到IBAction。在IBAction中编写,这样您就可以根据需要进行操作。
-(IBAction)editTableForDeletingRow
{
[addTagTableView setEditing:editing animated:YES];
}
,- (void)viewDidLoad {
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
使用此代码,您的应用程序中将有一个编辑按钮。如果按此按钮,\“红色减号\”将自动出现:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。