【发布时间】:2014-04-28 15:16:53
【问题描述】:
我正在构建主从应用程序,说主视图A(TableView),第二视图(tableview)B,细节视图C。数据来自核心数据。在 secondview(tableview) 中,当用户点击特定单元格时,popover 将提示单元格值更改。在弹出屏幕上更改后,关闭弹出窗口,它返回到 secondview(tableview) 并相应地更新核心数据。并且单元格值有望反映更新值。 问题是它不能那样工作。单元格值仍然是旧值,尽管核心数据已更新为新值(我通过 NSLOG 在方法 --tableview:cellForRowAtIndexPath 中确认了这一点。它打印单元格的新值,但显示单元格的旧值)。我试图将 table-view:reloaddata 放入 viewwillappear 和 popoverControllerDidDismissPopover 方法,但它仍然不起作用。
我想不通。 secondView(tableView) 上的单元格值只有在我将视图返回到主视图 A 并再次将其切换到第二视图 B 后才会更新。
但是,第二个视图会立即反映新添加的单元格,添加也是通过弹出框提示单元格新值输入。
有人可以帮忙吗?谢谢。
-(void) popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
//get text from popover based on various class type
if([popoverController.contentViewController isKindOfClass:[changecellvalueViewController class]])
{
NSString *thenewinputcellvalue =((changecellvalueViewController *)popoverController.contentViewController).thecellvalue.text;
NSString *oldcellvalue=((changecellvalueViewController *)popoverController.contentViewController).thecellvalueold.text;
if (0 != [ thenewinputcellvalue length] && oldcellvalue != thenewinputcellvalue) {
NSManagedObjectContext *acontext = [self.masterviewmasterController.fetchedResultsController managedObjectContext];
NSManagedObject *cellTobeChanged = ((changecellvalueViewController *)popoverController.contentViewController).cellobjecttobechanged;
[ cellTobeChanged setValue: thenewinputcellvalue forKey:@"cellvalue"];
// Save the context.
NSError *error = nil;
if (![acontext save:&error])
{
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
if (![self.masterviewmasterController.fetchedResultsController performFetch:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
[self.tableView reloadData];
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@“cell” forIndexPath:indexPath];
// Configure the cell...
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@“cell”];
}
NSManagedObject *celllist = [[SELF SORTCELLS] objectAtIndex:indexPath.row];
cell.textLabel.text = [[celllist valueForKey:@"cellName"] description];
NSLog(@"cell text %@", cell.textLabel.text);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
-
(void)viewDidLoad { [超级viewDidLoad];
// 取消注释以下行以保留演示文稿之间的选择。 // self.clearsSelectionOnViewWillAppear = NO;
// 取消注释以下行以在此视图控制器的导航栏中显示一个编辑按钮。 // self.navigationItem.rightBarButtonItem = self.editButtonItem; [self.tableView registerClass:[UITableViewCell 类] forCellReuseIdentifier:@"Cell"]; [self.tableView reloadData]; }
【问题讨论】:
-
你能粘贴几行你的代码吗?没有人可以帮助我想
-
检查coreData是否有值
标签: ios objective-c core-data uitableview