简体   繁体   English

iOS滑动以从UITableView删除plist中的数组

[英]iOS Swipe to Delete Array in plist from UITableView

I have a UITableView and in each row is the name of an array in a plist . 我有一个UITableView ,每一行是plist array的名称。 This means that when I try and use the normal swipe to delete method of: 这意味着当我尝试使用普通的滑动来删除以下方法时:

[tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic]

The app crashes. 该应用程序崩溃。 How can I tell the swipe to delete to find the array in the plist and delete it? 如何告诉刷卡删除以在plist中找到数组并将其删除?

It is not enough to delete the row being displayed in the table view. 删除表视图中显示的行还不够。 You also have to remove the item from your data array. 您还必须从数据数组中删除该项目。 Presumably you have a NSMutableArray that reads in the plist at the beginning. 大概您有一个NSMutableArray ,它在开始时从plist中读取。 (If it is just an NSArray , change it to mutable!) (如果它只是一个NSArray ,请将其更改为mutable!)

Just after deleting the row, delete the data from the array 删除行后,立即从数组中删除数据

[myDataArray removeObjectAtIndex:indexPath.row];

If you have sections, you first would have to figure out the position of your object in the array, but the principle is the same. 如果有部分,则首先必须弄清楚对象在数组中的位置,但是原理是相同的。

You can now optionally write the changes to disk by overwriting your existing plist with the contents of your data array. 现在,您可以选择用数据阵列的内容覆盖现有的plist,将更改写入磁盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM