This was stupid.
Anyone working with Mapkit - remember that any notifications that should result in a UI change should be dispatched to the main thread. I was dispatching them to a background worker thread so no wonder nothing was happening!
Вопрос
I have an MKMapView - which is working well. I now have some notifications that the ViewController responds to when the network coverage goes down. When this happens, I want to show a simple UIView with a UILabel that tells the user that the network is down.
I am having lots of lots of problems trying to achieve this. I have built the view in in the Interface Builder and I am initialising it like so in viewDidLoad:
self.networkWarningView = [[[NSBundle mainBundle] loadNibNamed:@"NetworkWarningView"
owner:nil
options:nil] lastObject];
self.networkWarningView.frame = CGRectMake((self.view.bounds.size.width / 2) - 140, (self.view.bounds.size.height / 2) - 45, 280, 70);
Then I am handling a network down notification using this method:
-(void)handleNetworkWarning
{
self.hasNetworkFailure = YES;
BOOL shouldBeAdded = YES;
for(UIView *view in [self.view subviews]){
if([view isEqual:self.networkWarningView]){
shouldBeAdded = NO;
}
}
if(shouldBeAdded){
self.networkWarningView.alpha = 0.0;
[self.view addSubview:self.networkWarningView];
[UIView animateWithDuration:0.7 animations:^{
self.networkWarningView.alpha = 1.0;
}];
}
}
I have tried adding the warningView to the view controller view AND the map view - but neither of these approaches work. I would like to 'animate in' the warning when it occurs.
Any advise to how to best overlay a view on an MkMapView would be appreciated. I thought it would be simple....
Thanks
Решение
This was stupid.
Anyone working with Mapkit - remember that any notifications that should result in a UI change should be dispatched to the main thread. I was dispatching them to a background worker thread so no wonder nothing was happening!