2016-02-16 127 views
1

運行的Xcode 7.2,當我收到以下錯誤多個視圖:線程1:信號SIGABRT -

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

確定例外文本中的關鍵字是「發送給實例的無法識別的選擇器」。如果你搜索,你會發現幾千個與這個常見的例外相關的問題。發帖前請先搜索。 – trojanfoe

+0

在您的項目中搜索「ViewHostsLayoutEngine」。發佈大量代碼是不好的。 – Lumialxk

+0

當您運行該項目時是否發生這種崩潰?我的意思是沒有與UI進行任何交互。 –

回答

0

爲什麼在應用代理的didFinishLaunching方法中設置rootViewController

self.window.rootViewController = quizVC; 

評論上面的loc,看它是否工作。

1

你的問題是不正確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'