gpt4 book ai didi

ios - 删除行前的确认

转载 作者:可可西里 更新时间:2023-11-01 05:06:31 25 4
gpt4 key购买 nike

我试图在实际从 UITableView 中删除单元格之前显示 UIAlertView

NSIndexPath *_tmpIndexPath;


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle == UITableViewCellEditingStyleDelete)
{
_tmpIndexPath = indexPath;

NSLog(@"%d", indexPath.row); // 2
NSLog(@"%d", _tmpIndexPath.row); // 2

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Dete" message:@"Are you sure you want to delete this entry?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil] autorelease];
[alert show];
}
}

所以我的两个日志都返回了正确的路径。

我有我的观点委托(delegate) UIAlertView

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%d", _tmpIndexPath.row);
if(buttonIndex == 1)
{
NSLog(@"%d", _tmpIndexPath.row);
}
}

现在我无法弄清楚为什么在 clickButtonAtIndex() 中尝试记录 _tmpIndexPath.row 时出现错误

 *** -[NSIndexPath row]: message sent to deallocated instance 0x12228e00

最佳答案

您将需要保留 indexPath,发生的情况是当警报被解除时您的 indexPath 已经从您的系统中释放,

像这样

改变

_tmpIndexPath = indexPath;

_tmpIndexPath = [indexPath retain];

关于ios - 删除行前的确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11079494/

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