如何从 uiviewcontroller 加载类中的方法
我正在尝试将 uitextfield 字符串从视图控制器传递到 nsobject 类中的方法...如果您能解释一下我是如何做到这一点的,那就太好了。
到目前为止,我已经完成了以下操作,但仍然出现很多错误。
NSObject Class dbAccess.h
- (void)passCode:(NSString *)passedCode;
NSObject Class.m
- (void)passCode:(NSString *passedCode {
myString = passedCodeVaraibel; //myString declared in .h
}
//...初始化数据库的其他代码。与 myString 或类似的东西,即使这可能是错误的,这就是为什么我问这个问题
viewController.m
//pass myCode textfield string when uitableviewcell is selected.
[dbAccess.passCode myCode.text];
我知道这是不对的,因为它不起作用:)但我希望它添加更多关于我正在尝试做的事情的细节。
I am trying to pass a uitextfield string from a view controller over to a method in a nsobject class... if you could please explain how I do this that would be great.
So far I have done the following however still getting lots of errors.
NSObject Class dbAccess.h
- (void)passCode:(NSString *)passedCode;
NSObject Class.m
- (void)passCode:(NSString *passedCode {
myString = passedCodeVaraibel; //myString declared in .h
}
//... other code to initialize the database. with myString or something to that effect even though this is probably wrong this is why im asking the question
viewController.m
//pass myCode textfield string when uitableviewcell is selected.
[dbAccess.passCode myCode.text];
I know this is not right because its not working :) but I hope it adds more detail as to what I am trying to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准 Objective-C 约定会要求您将方法名称更改为
setPassCode:
,但是passCode:
工作得很好。我假设这段代码无法编译,
要正确调用方法,请使用以下语法(几个示例):
如果要设置一个值,显然您希望将该值作为参数传递
Standard objective-c convention would request that you change the method name to
setPassCode:
, howeverpassCode:
works perfectly fine.i assume this code isn't compiling,
to correctly invoke a method, you use the following syntax (several examples):
if you want to set a value, obviously you want to pass in that value as a parameter