开发者

How to pass the parameters from a user-defined to delegate method in objective C (iPhone)

开发者 https://www.devze.com 2023-01-06 17:45 出处:网络
I want to ask about the passing parameter in objective C on iPhone simulator. Is it possible to pass an parameter (e开发者_运维知识库.g. NSArray) to the delegate method?

I want to ask about the passing parameter in objective C on iPhone simulator. Is it possible to pass an parameter (e开发者_运维知识库.g. NSArray) to the delegate method?

I wrote a program, when the user press a button, it will call a function called 'pressLoginButton' (user-defined). After complete the function, I have to pass an NSArray and NSString to the delegate method (connectionDidFinishLoading() in NSURLConnection class). Is it possible to do it?


connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[self setSavedProp:@"somevalue"];

since the delagate is "self", you can set a property on the current object/self/delegate

now in connectionDidFinishLoading(), access the property which contains the value you wanted

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
   // doSomething with value...
   [self savedProp];
}


It should be possible. Only problem can be with memory management (retain/release), if isn't properly handled.

0

精彩评论

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