I am currently using NSNotifications to send a message from my app delegate to a UIView in my iPhone application.
The notification gets received by the UIView and I then use a selector to change the state of a button on the UIView.
Here is the function that is passed to the selector:
-(void)changeButtonState
{
NSLog(@"Change button state received");
[testButton setEnabled:NO];
[testButton setNeedsDisplay];
}
This gets called however the button state never gets visually changed, it functionally becomes disabled but looks like its still enabled on the screen.
So it looks like setNeedsDisplay either doesn't work here or is incorrect coding on my part?
Can anyone tell me how I should properly redraw the button or view when I change the state?
Since UI refreshing is usually done on the main thread, setNeedsDisplay
will only get called on the main thread. Therefore, you need to make sure you are calling it on the main thread by using performSelectorOnMainThread
.