Xcode4, iOS: Certain parts of instance method being ignored, no errors, just passed by
new iOS guy here. I have a problem that Googling and searching on here has not shed any light on. I'm assuming this is basic. I have a simple app (app delegate and 1 view controller), and as part of it I'm using local notification. So, in the app delegate I use the 'didReceiveLocalNotification' to watch for the notifications. Depending on which one comes in, I then call one of several instance methods in my main view controller.
ie in the AppDelegate.m
- (void)application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification {
MyViewController* controller = [[MyViewController alloc] autorelease];
if ([[notification.userInfo objectForKey:@"id"] isEqualToString:@"myKey"]) {
[controller checkActive];
}
}
Through logging and watching some breakpoints, this is all working. If the app is in the background, the notification comes in, app opens, and the correct instance method is called.
What I cannot figure out at all is why some parts of the instance method are simply being passed by, with no effect. For a simple example, if we have this:
-(void)checkActive {
ViewThing.alpha = 1.0;
NSLog(@"checkActive ran");
}
The log statement will show up fine, but the ViewThing will not change. Elsewhere in the main view c开发者_如何转开发ontroller I'm calling the same checkActive method with no problems and it changes the ViewThing. (via another interface button IBAction method in that case).
There are no errors, no warnings, the console shows nothing, putting a breakpoint on ViewThing shows that it hits the line. I'm stumped, cannot see what is different from trying to calling the method from the delegate vs. on an IBAction.
Thanks for any tips!
If the alpha
is not correctly changing there a few possible issues with 1 and 2 being the most likely.
ViewThing
isnil
. Reasons could be is the view unloaded and you set it to nil or checkActive was called before the outlets were set.ViewThing.alpha
is being set on a thread that is not the main thread. Attempting to change UI elements on a separate thread will caused undefined behavior such as never updating the change or taking an extended amount of time to update the change. You can check if it is the main thread using[NSThread isMainThread]
.ViewThing
is pointing a different view.
1 & 2 can easily be checked by logging view
NSLog(@"checkActive ran %@", ViewThing);
精彩评论