将 NSManagedObject 的属性引用传递给另一个视图控制器以编辑值
问题:我有一个标准子类 NSManagedObject (见下文)。我有一个视图控制器,我想用它来编辑 NSManagedObject 的所有 NSString* 。我只想传递对下面任何 NSString* 的指针的引用进行编辑。我该怎么做?有没有更好的方法来设置编辑屏幕和参考?现在,我将整个 NSManagedObject * 传递给编辑 ViewController,然后使用整数来更新/编辑我想要从 NSManagedObject 编辑的正确属性。
有没有更优雅的方法来做到这一点?我还没有看到一个很好的干净的例子来编辑核心数据中的实体,并且对界面设计相对较新。
NSManagedObject:
@interface MySounds : NSManagedObject {
}
@property (nonatomic, retain) NSString * soundOne;
@property (nonatomic, retain) NSString * soundTwo;
@property (nonatomic, retain) NSString * soundThree;
编辑界面:
@interface EditItemViewController : UIViewController
<UITextViewDelegate>
{
MySounds *sounds;
int fieldToEdit;
...
}
@property (nonatomic, assign) MySounds *toSave;
@property (nonatomic) int fieldToEdit;
我如何使用 int 和 MySounds * 的示例:
- (void) viewDidLoad
{
switch (fieldToEdit)
{
...
case 2:
{
[self.textField setText:[self.sounds soundOne]];
}
...
}
...
}
Issue: I have a standard subclassed NSManagedObject (see below). I have a view controller I'd like to use to edit all of the NSString* 's of the NSManagedObject. I only want to pass a reference to the pointer of any of the NSString* 's below to edit. How can do I do this? Is there a better way to setup editing screens and references? Right now I'm passing the entire NSManagedObject * to the editing ViewController, then do a hack job of using an integer to update/edit the correct property I want to edit from the NSManagedObject.
Is there a more elegant way of doing this? I've yet to see a nice clean example of working with editing entities from core data and am relatively new to interface design.
NSManagedObject:
@interface MySounds : NSManagedObject {
}
@property (nonatomic, retain) NSString * soundOne;
@property (nonatomic, retain) NSString * soundTwo;
@property (nonatomic, retain) NSString * soundThree;
The Edit Interface:
@interface EditItemViewController : UIViewController
<UITextViewDelegate>
{
MySounds *sounds;
int fieldToEdit;
...
}
@property (nonatomic, assign) MySounds *toSave;
@property (nonatomic) int fieldToEdit;
Example of how I use the int and MySounds *:
- (void) viewDidLoad
{
switch (fieldToEdit)
{
...
case 2:
{
[self.textField setText:[self.sounds soundOne]];
}
...
}
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊。别介意整个问题。
我忘记了 nsmanagementobjects 的键值编码:)
Ugh. Nevermind the entire question.
I forgot about key-value coding with nsmanagedobjects :)