Search code examples
iosexceptionviewdidload

I Could not solved this NSInvalidArgumentException


Here is my code:

@interface TabRegsViewController ()
@end

@implementation TabRegsViewController

@synthesize parent;
@synthesize menu_select;

-(BOOL) shouldAutorotate {    
    return UIInterfaceOrientationMaskPortrait;
}

-(NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad {
    NSLog(@"***************\t\t\tTab_Reg_ViewDidLoad");
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidAppear:(BOOL)animated {
    //[super viewDidAppear:animated];
    NSLog(@"***************\t\t\tTab_Reg_ViewDidAppear");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

This UI only makes the storyboard.

This storyboard plays in an iPhone 5, however my iPhone 6 Plus cannot.

************* tab_reg_ViewDidload

terminating app to uncaught exception

'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects: count: ]: attempt to insert nil object from objects[0]'

I don't know what to do.

After this parent class button event happens, presentViewController event occurs and the page changes.

iPhone 5 works but iPhone 6 plus fails.

I think this TabRegsViewController viewDidLoad is okay, but an exception.

I don't know how to clear this exception.

Please help me.

Edit :

This Class Call method, and this vc pointer and self is nil. why?..

UIStoryboard *storyboard = [UIStroyboard storyboardWithName:"Main_Storyboard" bundle:nil];
TabRegsViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"TabRegsViewController"];
vc.parent = self;
[self presentViewController:vc animated:NO completion:nil];

and current exception point is

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromclass([Appdelegate class]));
    }
}

error is Thread 1: signal SIGABRT argc (int) argv = (unsigned char ** )NULL


Solution

  • Seems like the nibNameOrNil is nil, add a breakpoint to the line below. And tell us what you get.

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
         //Add a breakpoint overhere or NSLog the value nibNameOrNil and nibBundleOrnil
         self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
    }
    

    Follow up answer: Okay, from reading those screenshot I can only have a rough idea of your structure. And the code looks fine. From my experience, this error

    'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects: count: ]: attempt to insert nil object from objects[0]'
    

    is usually happens when you calling some method but some parameter are missing.

    You mentions

    This Class Call method, and this vc pointer and self is nil. why?..

    you add a breakpoint at which position and find out that self is nil?? need more code for me to trace the error||