English 中文(简体)
从查看控制器到实体类方法的参数
原标题:Pass Value as Parameter from View Controller to Method of Entity Class

我有一个带有 UIText Field 的 View 控制器。 用户将字符串输入文本字段, 单击完成的按钮, 然后此值应传递到实体类中的一种方法 。 我知道我需要将此值作为参数传递, 但我卡住了 。

我试图通过在点击 Done IB Action 结尾处添加一个参数来传递此值, 以便让完成的按钮没有运气 。 感谢您哪怕是最小的帮助或指向正确的方向 。

- (IBAction)doneClicked:(NSString*) name {
...
}

我在实体的h类文件中尝试过为 View Connator 创建一个 ivar, 但是 Xcode 问道 : “ 未知的型号 View Connator ; 你是说 UIView?

@interface EntityClass : NSManagedObject{
ViewController* refVC;
UITextField* textBox;
}

并然后使用

self.name = self.refVC.textBox.text; 

在实体类m文件我的方法中返回 NSString 本身。 name

最佳回答

我想通了 这是我最后的密码 起作用了 不再需要帮助了

谢谢!

- (IBAction)doneClicked:(NSString*) name {
...

superClass.name = headingText.text;  //headingText is UITextField on ViewController

[superClass doSomething];
...
}
问题回答

不要将“视图控制器”传送到“实体对象”中。 相反, 请在您的“ 点击” 动作中更新“ 实体对象” 属性 。

- (IBAction)doneClicked:(NSString *)name {
   myObject.name = name;
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签