我正在开发一个 iPhone 应用程序,但发生了一些奇怪的事情。我想我可以向你征求意见。
我实现了一个 TableView 和一个自定义视图作为创建新对象表单。当 TableView 工具栏中的用户选项卡“添加”按钮时,我使自定义视图向上滑动,如下面的代码:
- (void)slide_up_form:(id)sender {
CustomViewController *controller = [[CustomViewController alloc] init];
// Assign this controller to use add_entity: message to TableView.
controller.parent = self;
[self presentModalViewController:controller animated:TRUE];
}
// To update TableView presentation.
-(void)add_block:(Block *)newBlock
{
[blockArray insertObject:newBlock atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tblCameraList insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
[self.tblCameraList scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
在自定义视图中,用户填写表单和选项卡“保存”按钮。所以我确实将实体保存到核心数据。并且需要用新对象更新 TableView,所以我在自定义视图中编写以下语句:
@synthesize parent;
- (void)save_block:(id)sender {
// save entity.
[self.parent add_block:newBlock];
// Slide down the custom view and show the TableView.
[[self parentViewController] dismissModalViewControllerAnimated:TRUE];
}
我已经在模拟器和 iPhone 中对此进行了测试。当用户选项卡“保存”按钮时,应用程序保存了新实体,但它不会使用新条目更新 TableView。
你能给你的建议来解决这个问题吗?