passing variables when calling methon in new thread (iphone)

Posted by Mouhamad Lamaa on Stack Overflow See other posts from Stack Overflow or by Mouhamad Lamaa
Published on 2011-01-13T09:29:01Z Indexed on 2011/01/13 12:54 UTC
Read the original article Hit count: 166

dear stacks

i need to pass variables to the thread method when creating a new thread

my code is the follwing //generating thread

[NSThread detachNewThreadSelector:@selector(startThread) toTarget:self withObject:nil];

thread job

- (void)startThread:(NSInteger *)var img:(UIImageView *) Img{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    [NSThread sleepForTimeInterval:var];
    [self performSelectorOnMainThread:@selector(threadMethod) withObject:nil waitUntilDone:NO];

//i need to pass Img to threadMethod: [pool release]; } thread Method

 - (void)threadMethod:(UIImageView *) Img {
        //do some coding.
    }

so how i can do this (pass parameter to both of methods

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c