这是我关于stackoverflow的第一篇文章.非常感谢您的任何帮助!
我对ios开发完全陌生.作为一种做法,我正在尝试开发一个简单的应用程序,在我的实验室中跟踪不同的项目.每个项目与其位置具有一对一关系,并且每个位置与不同项目具有多对多关系.
我有一个UITableViewController(LocationListTableViewController)使用NSFectchedResultController作为实现代码如下它的数据源.tableview控制器也符合NSFetchedResultControllerDelegate以保持所有NSManagedObject更新.
点击一个位置后LocationListTableViewController,DetailedTableViewController将按下a并显示该位置的项目.这DetailedTableViewController有一个NSUndoManager实例变量来支持取消更改.我用a NSMutableArray作为数据源DetailedTableViewController:
NSSet *items = self.location.items;
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"itemName" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *array = [[items allObjects]sortedArrayUsingDescriptors:sortDescriptors];
// itemList is the data source for the table view
self.itemList = [array mutableCopy];
Run Code Online (Sandbox Code Playgroud)
点击"编辑"按钮后,用户可以删除项目,并将这些项目的位置设置为零.已删除的项目将转移到"changedItem"NSMutableArray,以便可以取消更改:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!changedItems)
changedItems = [[NSMutableArray alloc] init];
// Set the company attribute of …Run Code Online (Sandbox Code Playgroud)