开发者

How do I load a method thats in a class from a uiviewcontroller

开发者 https://www.devze.com 2023-03-12 15:30 出处:网络
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 开发者_Python百科I do this that would be great.

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 开发者_Python百科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.


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消