我不知道为什么,但是当我使用xib时没有问题。
错误消息如下:
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
最佳答案
将您的@selector(applicationDidBecomeActive :)更改为@selector(applicationDidBecomeActive)
由于您的方法签名是- (void)applicationDidBecomeActive
关于ios - 当我使用 Storyboard 时,无法识别applicationWillResignActive的功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23129474/