gpt4 book ai didi

ios - 尝试通过 UITableViewCell 的滑动手势更新 FMDB

转载 作者:行者123 更新时间:2023-11-29 12:59:52 24 4
gpt4 key购买 nike

有没有办法通过 UITableViewCell 的滑动手势来更新 FMDB?我希望能够使用现有的删除按钮来更改表中的单个列,但我尝试的所有操作似乎都会导致应用程序崩溃。我还希望能够创建一个插入按钮来执行类似的操作,但如果不创建 subview 就无法找到执行此操作的代码。我发布了一个我尝试过的事情的例子。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source

[tableView deleteRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationFade];

NSString *docsDir;
NSArray *dirPaths;

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // Get the documents directory

docsDir = dirPaths[0];

NSString *path = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"passages.db"]];

self.database = [FMDatabase databaseWithPath:path];
[self.database open];

[self.database executeUpdate:@"UPDATE passages set favorite=?", @NO, nil];
[self.database close];

}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
[self.tableView reloadData];

最佳答案

试试这个:

//Doing this should give you the swipe to delete functionality out of the box
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//your code for updating favorite
}
}

关于ios - 尝试通过 UITableViewCell 的滑动手势更新 FMDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20058872/

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