ios - 线程 1 : signal SIGABRT - multiple views

标签 ios objective-c xcode sigabrt

我在运行 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 文件上,但我无法理解错误。任何帮助将不胜感激。

在此先感谢您的帮助/建议!

最佳答案

您的问题是 tabbarController 的 属性分配不正确:

   tb.viewControllers = @[quizVC, vc2,vc3];

它应该是 UIViewControllers(或其子类)的实例数组。但是你有 VC3 的定义:

@interface VC3 : UIView
{
    UIBezierPath *path;
}

什么意思是将 UIView 的子类放在数组 tb.viewControllers 而不是 UIViewControllers 中。因此,您需要分配 ViewControllers 数组,而不是views。这就是为什么 tabbarController 会出现 -[VC3 _setViewHostsLayoutEngine:]: unrecognized selector sent to instance 0x7feea354edc0' 异常。

关于ios - 线程 1 : signal SIGABRT - multiple views,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35428261/

相关文章:

objective-c - Addresponse - 仅添加到内存(XCode)

ios - 由于未捕获的异常 'NSInternalInconsistencyException' 错误而终止应用程序

ios - 将数据从初始 View Controller 传递到最后一个 View Controller

ios - CVPixelBuffer 到 NSData 并返回

iphone - 点击iPhone通知中心的消息时如何转到特定 View ?

ios - 从 UTC 字符串获取日期

objective-c - AutoreleasePool 没有捕获断点,没有警告,Instruments Leaks 中没有报告

iphone - 如何创建一个每周更新的类似 iPhone 应用程序的新闻

ios - 停止 View Controller 上的计时器解雇 swift

ios - TableView 中混合 UIPicker 和 TextField