gpt4 book ai didi

iphone - UITableView编辑疑惑

转载 作者:行者123 更新时间:2023-11-28 20:38:38 24 4
gpt4 key购买 nike

我有从数据库中删除单元格内容的代码

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

if (editingStyle == UITableViewCellEditingStyleDelete) {
[appDelegate.indexArray removeObjectAtIndex:indexPath.section];
[appDelegate.notesArray removeObjectAtIndex:indexPath.section];
[tableViewObj reloadData];
NSString *DataPath = [MyBibleAppAppDelegate getPath];
[appDelegate.data writeToFile:DataPath atomically:YES];
[tableViewObj reloadData];
}
}

它工作完美,但我需要将上面的代码放在我的按钮点击中,我把它放在按钮点击中

-(IBAction)_clickbtndeltNoteall:(id)sender
{
[appDelegate.indexArray removeObjectAtIndex:indexPath.section];
[appDelegate.notesArray removeObjectAtIndex:indexPath.section];
[tableViewObj reloadData];
NSString *DataPath = [MyBibleAppAppDelegate getPath];
[appDelegate.data writeToFile:DataPath atomically:YES];
[tableViewObj reloadData];
}

但我得到了这个错误:“未声明的标识符索引路径”。如何解决?

最佳答案

我建议在单例中保存按下行的 indexPath。这是有关如何使用 singleton class 的指南存储对象并跨类使用它们。

在此示例中,您还可以只声明一个实例变量,并在按下行时为您的 UITableView 适当的委托(delegate)方法设置它。可以这样做:

@interface

NSIndexPath *tableViewPath;

@implementation

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

tableViewPath = indexPath;

}

您的按钮操作现在应如下所示:

- (IBAction)_clickbtndeltNoteall:(id)sender
{
[appDelegate.indexArray removeObjectAtIndex:indexPath.section];
[appDelegate.notesArray removeObjectAtIndex:indexPath.section];
[tableViewObj reloadData];
NSString *DataPath = [MyBibleAppAppDelegate getPath];
[appDelegate.data writeToFile:DataPath atomically:YES];
[tableViewObj reloadData];
}

按钮的代码假设在按下之前已经选择了一行。您还可以在 viewDidLoad 中初始化您的 indexPath像这样:

@implementation

- (void)viewDidLoad {

tableViewPath = [NSIndexPath indexPathForRow:0 inSection:0];

}

您应该调整您的初始化以适合您的特定程序!

关于iphone - UITableView编辑疑惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9514387/

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