我想编辑一个CoreData对象,当用户单击UITableView中的一个单元格基于cell.accessoryType来显示该项目是否已被点击。这是当前的代码。更新/编辑核心数据管理对象
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSManagedObject *itemToUpdate = [groceryArray objectAtIndex:indexPath.row];
NSLog(@"updating: %@", itemToUpdate);
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
itemToUpdate.purchased = NO;
}else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
itemToUpdate.purchased = YES;
}
// Commit the change.
NSError *error;
if (![managedObjectContext save:&error]) {
// Handle the error.
NSLog(@"Saving changes failed: %@", error);
}
}
这似乎是选择合适的对象,因为的NSLog()会显示正确的项目,但是当我尝试使用点符号例如更新“itemToUpdate.purchased = YES;”编译器会在“不是结构或联合”的东西中抛出一个错误“购买成员的请求”。
我知道我可能做错了(我在xcode中的第一个项目) - 任何意见将不胜感激!
感谢
谢谢!这工作...我有很多阅读要做。感谢你的时间和帮助。 :) – lostincode 2010-12-03 09:48:31