This’s my first time I use KVO and I got stuck right away. The problem is that when observeValueForKeyPath get called I’m calling another method in the same class. And that method is just showing an alert view. Simple things I thought, but the alert view dosen’t show.
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
[self beginUpdate];
}
-(void)beginUpdate
{
NSLog(@"Check!");
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"message" message:@"Hi" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
The log message shows up. The alert message only shows if I call it from any other method than observeValueForKeyPath.
As far as I know,
observeValueForKeyPath:is called in the context of the thread that modified the observed object. On the other hand, changes to the UI must only be done on the main thread. Tryor
to ensure that the
UIAlertViewis created on the main thread.