2014-01-23 34 views
0

我有一个目的地视图控制器,允许您编辑显示在TableViewController中的信息..我试图设置它在一个自定义单元格..我有我的UITableViewCell文件与自定义属性类和我也有我的模型类的核心数据与属性。我设法让我的根表视图控制器显示自定义标签,当我添加一个新的播放器,但一旦我点击单元格并在新的视图控制器中编辑它会回到表视图的默认值。我相信这与代码有关,但我无法弄清楚。自定义TableViewCell与核心数据

我NsManagedObject子类

@property (nonatomic, retain) NSString *playerFirstName; 

我有一个指针currentPlayer我的球员在类我viewcontroller.h文件和firstnameTextfield是我的UITextField

-(IBAction)doneEditing:(id)sender { 

_currentPlayer.playerFirstName = firstnameTextField.text; 

AppDelegate *myApp = (AppDelegate *) [[UIApplication sharedApplication]delegate]' 
[myApp saveContext]; 

} 

更新

我相信这是我的代码行后,它是与它搞砸的问题

_currentPlayer.playerFirstName = firstnameTextField.text; 

我怎么了currentPlayer指针去我playerNameCell财产在我customcell类

+0

对不起,如果我的术语关闭我还在学习 – Blake

+0

当你回到主视图,你是否重新加载行(或表)来显示新的数据? (例如'[self.tableView reloadData];' –

+0

我正在使用[self.tableView beginUpdates] - (void)controllerWillChangeContent方法和didChange方法 – Blake

回答

1

你应该这样做:

- (IBAction)newPlayer { 
    _currentPlayer = (Player*) [NSEntityDescription insertNewObjectForEntityForName:@"Player" inManagedObjectContext:_managedObjectContext]; 
} 

_managedObjectContext应该传递给视图控制器从应用程序委托或其他视图控制器。