gpt4 book ai didi

ios - 当我使用 UIActionSheet 确认时删除 TableView 中的行

转载 作者:行者123 更新时间:2023-11-28 19:14:44 25 4
gpt4 key购买 nike

我使用 UIActionSheet 来确认删除 TableView 中的行。我有 3 行但是当我交换删除第一行时,第一行没有删除但第三行被删除。在我继续再次删除第一行但第二行被删除之后。我不知道为什么。请帮我解决这个小问题。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{

if (editingStyle == UITableViewCellEditingStyleDelete)
{

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"Delete" otherButtonTitles: nil];

[actionSheet showInView:self.view];

}

}





-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{


switch (buttonIndex) {
case 0:

[listOfName removeObjectAtIndex:self.selectedIndex];
//selectedIndex = indexPath.row;
[self viewWillAppear:YES];

}


}

最佳答案

问题来了

[listOfName removeObjectAtIndex:self.selectedIndex];

UIActionSheetselectedIndex 的值始终为 0,因为它未设置为要删除的表行的索引。

在呈现 UIActionSheet 之前将其值设置为 indexPath.row

self.selectedIndex = indexPath.row;
[actionSheet showInView:self.view];

然后在 case 0 中的 clickedButtonAtIndex: 方法中,确保重新加载 TableView 。

[tableView reloadData];

关于ios - 当我使用 UIActionSheet 确认时删除 TableView 中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13029957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com