2016-02-16 3 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

OK ключевые слова в тексте исключения - это «непризнанный селектор, отправленный в экземпляр». Если вы ищете, вы найдете буквально тысячи вопросов, связанных с этим очень распространенным исключением. Пожалуйста, выполните поиск перед публикацией. – trojanfoe

+0

Поиск «ViewHostsLayoutEngine» в вашем проекте. Плохо разместить много кода. – Lumialxk

+0

Происходит ли это сбой при запуске проекта? Я имею в виду без каких-либо взаимодействий с пользовательским интерфейсом. –

ответ

0

Почему вы устанавливаете rootViewController в методе делегата приложения didFinishLaunching?

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' исключение.