0
我不知道为什么。但是当我使用xib时,没有任何问题。当我使用故事板时,applicationWillResignActive的功能无法识别
错误信息是这样的:
2014-04-17 16:59:11.413 State Lab[2227:60b] Cannot find executable for CFBundle 0x8d800c0 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)
2014-04-17 16:59:11.453 State Lab[2227:60b] application:didFinishLaunchingWithOptions:
2014-04-17 16:59:11.459 State Lab[2227:60b] applicationDidBecomeActive:
2014-04-17 16:59:11.461 State Lab[2227:60b] -[spsViewController applicationDidBecomeActive:]: unrecognized selector sent to instance 0x8f8f390
2014-04-17 16:59:11.463 State Lab[2227:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[spsViewController applicationDidBecomeActive:]: unrecognized selector sent to instance 0x8f8f390'
*第一掷调用堆栈:
我的代码:
#import "spsViewController.h"
@interface spsViewController()
@property (assign, nonatomic) BOOL animate;
- (void)rotateLabelUp;
- (void)rotateLabelDown;
@end
@implementation spsViewController
@synthesize label, animate;
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:[UIApplication sharedApplication]];
CGRect bounds = self.view.bounds;
CGRect labelFrame = CGRectMake(bounds.origin.x, CGRectGetMidY(bounds) - 50, bounds.size.width, 100);
self.label = [[UILabel alloc] initWithFrame:labelFrame];
label.font = [UIFont fontWithName:@"Helvetica" size:70];
label.text = @"Bazinga!";
label.textAlignment = NSTextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
[self.view addSubview:label];
[self rotateLabelDown];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
self.label = nil;
}
- (void)rotateLabelDown
{
[UIView animateWithDuration:5
animations:^{
label.transform = CGAffineTransformMakeRotation(M_PI);
}
completion:^(BOOL finished){
[self rotateLabelUp];
}];
}
- (void)rotateLabelUp
{
[UIView animateWithDuration:5
animations:^{
label.transform = CGAffineTransformMakeRotation(0);
}
completion:^(BOOL finished){
if (animate)
[self rotateLabelDown];
}];
}
- (void)applicationWillResignActive
{
NSLog(@"VC: %@", NSStringFromSelector(_cmd));
animate = NO;
}
- (void)applicationDidBecomeActive
{
NSLog(@"VC: %@", NSStringFromSelector(_cmd));
animate = YES;
[self rotateLabelDown];
}
@end
你的方法没有参数......你说,它有一个当你设置的通知(你把“:”)。 – Larme