passing variables when calling methon in new thread (iphone)
- by Mouhamad Lamaa
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