简体   繁体   English

具有核心数据的自定义TableViewCell

[英]Custom TableViewCell with Core Data

I have a Destination View Controller that allows you to edit information displayed in the TableViewController..I am attempting to set this up in a custom cell..I have my UITableViewCell file with the custom property class and I also have my Model Class for the Core Data with the attributes. 我有一个Destination View Controller,它允许您编辑TableViewController中显示的信息。.我试图在自定义单元格中进行设置。.我的UITableViewCell文件带有自定义属性类,我也有模型类具有属性的核心数据。 I managed to get my root table view controller to show the custom label when I add a NEW player but once I click on the cell and edit it in the new view controller it goes back to the default on the table view. 添加播放器时,我设法使根表视图控制器显示自定义标签,但是一旦单击该单元格并在新视图控制器中对其进行编辑,它就会恢复为表视图的默认值。 I believe it has something to do with this code but I can not figure it out. 我相信这与这段代码有关,但我无法弄清楚。

my NsManagedObject Subclass 我的NsManagedObject子类

@property (nonatomic, retain) NSString *playerFirstName;

I have a pointer to my Player Class of currentPlayer in my viewcontroller.h file and the firstnameTextfield is my UITextField 我的viewcontroller.h文件中有一个指向currentPlayer播放器类的指针,而firstnameTextfield是我的UITextField

-(IBAction)doneEditing:(id)sender {

_currentPlayer.playerFirstName = firstnameTextField.text;

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

}

Update 更新

I believe this is my line of code that is the problem after messing with it 我相信这是我的代码行,弄乱后就是问题

_currentPlayer.playerFirstName = firstnameTextField.text;

how do I get the currentPlayer pointer to go to my playerNameCell property in my customcell class 如何获取currentPlayer指针以转到我的customcell类中的playerNameCell属性

You should do something like: 您应该执行以下操作:

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

The _managedObjectContext should be passed to the view controller from the app delegate or some other view controller. _managedObjectContext应该从应用程序委托或其他一些视图控制器传递给视图控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM