如何从 uiviewcontroller 加载类中的方法

发布于 2024-11-15 14:35:27 字数 601 浏览 4 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在风中等你 2024-11-22 14:35:27

标准 Objective-C 约定会要求您将方法名称更改为 setPassCode:,但是 passCode: 工作得很好。

我假设这段代码无法编译,
要正确调用方法,请使用以下语法(几个示例):

[target action:argument];
[target action:arg1 anotherParameter:arg2];
[target action]

如果要设置一个值,显然您希望将该值作为参数传递

// DBAccess.m
- (void)setPassCode:(NSString *)newPassCode {
   myString = newPassCode; // myString defined as ivar in .h
}


dbAccess = [[DBAccess alloc] init]; 
// …
[dbAccess setPassCode:textField.text];

Standard objective-c convention would request that you change the method name to setPassCode:, however passCode: works perfectly fine.

i assume this code isn't compiling,
to correctly invoke a method, you use the following syntax (several examples):

[target action:argument];
[target action:arg1 anotherParameter:arg2];
[target action]

if you want to set a value, obviously you want to pass in that value as a parameter

// DBAccess.m
- (void)setPassCode:(NSString *)newPassCode {
   myString = newPassCode; // myString defined as ivar in .h
}


dbAccess = [[DBAccess alloc] init]; 
// …
[dbAccess setPassCode:textField.text];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文