运行xcode 7.2时,我收到以下错误:
2016-02-16 04:02:42.591 Hello1[1287:44519] -[VC3 _setViewHostsLayoutEngine:]: unrecognized selector sent to instance 0x7feea354edc0
2016-02-16 04:02:42.598 Hello1[1287:44519] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VC3 _setViewHostsLayoutEngine:]: unrecognized selector sent to instance 0x7feea354edc0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010568fe65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000105108deb objc_exception_throw + 48
2 CoreFoundation 0x000000010569848d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001055e590a ___forwarding___ + 970
4 CoreFoundation 0x00000001055e54b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000105c2fd79 -[UITabBarController _setViewControllers:animated:] + 248
6 UIKit 0x0000000105c30e58 -[UITabBarController setViewControllers:animated:] + 119
7 Hello1 0x0000000104bfda7b -[AppDelegate application:didFinishLaunchingWithOptions:] + 875
8 UIKit 0x0000000105a331f1 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
9 UIKit 0x0000000105a34397 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3415
10 UIKit 0x0000000105a3acc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
11 UIKit 0x0000000105a37e7b -[UIApplication workspaceDidEndTransaction:] + 188
12 FrontBoardServices 0x000000010840b754 -[FBSSerialQueue _performNext] + 192
13 FrontBoardServices 0x000000010840bac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
14 CoreFoundation 0x00000001055bba31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x00000001055b195c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x00000001055b0e13 __CFRunLoopRun + 867
17 CoreFoundation 0x00000001055b0828 CFRunLoopRunSpecific + 488
18 UIKit 0x0000000105a377cd -[UIApplication _run] + 402
19 UIKit 0x0000000105a3c610 UIApplicationMain + 171
20 Hello1 0x0000000104c004df main + 111
21 libdyld.dylib 0x0000000107dcb92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是我的main.m
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
AppDelegate.m
#import "AppDelegate.h"
#import "MyViewController.h"
#import "ViewController.h"
#import "VC2.h"
#import "VC3.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CGRect mainRect = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame: mainRect];
MyViewController *quizVC = [[MyViewController alloc] init];
self.window.rootViewController = quizVC;
//MyViewController *quizVC2 = [[MyViewController alloc] init];
//self.window.rootViewController = quizVC;
VC2 * vc2 = [[VC2 alloc] init];
VC3 * vc3 = [[VC3 alloc] init];
//ViewController * vc1 = [[ViewController alloc] init];
//self.window.rootViewController = vc1;
UITabBarController * tb = [[UITabBarController alloc] init];
tb.viewControllers = @[quizVC, vc2,vc3];
self.window.rootViewController = tb;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
VC3.h
#import <UIKit/UIKit.h>
@interface VC3 : UIView
{
UIBezierPath *path;
}
@end
VC3.m
import "VC3.h"
@interface VC3 ()
@end
@implementation VC3
/*-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName: nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.title = @"Drawer";
}
return self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}*/
- (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event
{
// Initialize a new path for the user gesture
self->path = [UIBezierPath bezierPath];
path.lineWidth = 4.0f;
UITouch *touch = [touches anyObject];
[path moveToPoint:[touch locationInView:self]];
}
- (void) touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event
{
// Add new points to the path
UITouch *touch = [touches anyObject];
[self->path addLineToPoint:[touch locationInView:self]];
[self setNeedsDisplay];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
[path addLineToPoint:[touch locationInView:self]];
[self setNeedsDisplay];
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesEnded:touches withEvent:event];
}
- (void) drawRect:(CGRect)rect
{
// Draw the path
[path stroke];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// All BNRHypnosisViews start with a clear background color
self.backgroundColor = [UIColor clearColor];
}
return self;
}
/*-(void) loadView
{
VC3 *hv = [[VC3 alloc] initWithFrame:CGRectZero];
[hv setBackgroundColor:[UIColor blueColor]];
[self setView: hv];
[hv release];
} */
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
我是objective-c和xcode的新手,所以请原谅我所犯的任何“新手”错误。我确信问题出现在我的VC3.m文件中,但我无法理解错误。任何帮助将不胜感激。
提前感谢您的帮助/建议!
答案 0 :(得分:2)
您的问题不正确tabbarController's
属性分配:
tb.viewControllers = @[quizVC, vc2,vc3];
它应该是UIViewControllers(或它的子类)的实例数组。但是你有VC3的定义:
@interface VC3 : UIView
{
UIBezierPath *path;
}
什么意思是你把UIView的子类放在数组tb.viewControllers
而不是UIViewControllers中。因此,您需要分配 ViewControllers 的数组,而不是视图。这就是tabbarController提升-[VC3 _setViewHostsLayoutEngine:]: unrecognized selector sent to instance 0x7feea354edc0'
例外的原因。
答案 1 :(得分:0)
为什么要在App委托的rootViewController
方法中设置didFinishLaunching
?
self.window.rootViewController = quizVC;
评论上面的loc并查看它是否有效。