I’m very new to IOS programming and i have doubt with NSThread.
My problem is, i have a UILabel in my view and i want to hide and make it visible Successively after every 5 second.
For this purpose i’ve used NSThread as below.
[NSThread detachNewThreadSelector:@selector(animate) toTarget:self withObject:nil];
-(void) animate
{
while(animateLabel){
[NSThread sleepForTimeInterval:5];
if(label.hidden){
NSLog(@"Label is hidden");
[label setHidden:NO];
}else
{
NSLog(@"Label is vissible");
[label setHidden:YES];
}
}
}
Now i’m getting “Label is hidden” and “Label is vissible” Successively in log after every 5 seconds. But my label is not getting hide.
I did with NSTimer and it’s working.
But, what is the problem with above code ?. If no problem with this code, Why NSThread couldn’t do ?
You need to perform this on a main thread instead.
Try this –
since you have while loop
remove sleep and add runloop