0

I need to open a registration form on my application programatically, the view controller is created on storyborad with storybpard ID ViewControllerRegister and the code I have used to open the form is

RegistrationFormViewController *registerView = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerRegister"];
          [self presentViewController:registerView animated:NO completion:nil];

But when I run the application, I am getting the error like,

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' * First throw call stack:

4
  • Have u added the storyboard id as similar. Commented Feb 8, 2016 at 11:15
  • Yes the name is ViewControllerRegister. Commented Feb 8, 2016 at 11:15
  • no problem not in RegistrationFormViewController here , check after the present you were add some nil value to your array , that the error Commented Feb 8, 2016 at 11:16
  • Make sure you have initialized your array Commented Feb 8, 2016 at 11:18

3 Answers 3

1

1) Make sure about your storyboardname is "Main" or different.

enter image description here

2) Check you have entered proper storyboard identifier.

enter image description here

and Finally,

3) Sometimes Xcode can't able to find storyboard with self.storyboard. Try to mention storyboard with actual name like,

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

        RegistrationFormViewController *registrationFormViewController = [storyBoard instantiateViewControllerWithIdentifier:@"RegistrationFormViewController"];
        [self presentViewController:registrationFormViewController animated:YES completion:nil];
Sign up to request clarification or add additional context in comments.

4 Comments

Basically my application is slider menu with navigation view controller. I need to pop the registration form if the device not registered on when the application launches. And I have put the above below - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];
Do you have any demo for that ?
I am following the tutorial here archetapp.com/2014/07/14/…
I need to show your code. I can't understand your scenario. You are trying it from side menu or simple your viewcontroller ? and what you want to do ? pop or present ?
1

[__NSArrayM insertObject:atIndex:]: object cannot be nil, the error says Look in your code for any lines that say "insertObject:atIndex:". The object you're inserting is apparently nil.

Make sure you have initialized your array called XXXX before adding any object into it...

NSMutableArray *xxx=[[NSMutableArray alloc]init];

and stop adding any nil object into it...

if(str) //or if(str != nil) or if(str.length>0)
{
//add the str into xxx array.
}
else
{
 //add the empty value to your xxx array
}

Comments

1

There is no problem in your code for loading a view controller programmatically. You must check with breakpoint that either your viewDidLoad method is being called in your opening controller or not. If it is being called then everything is fine and you need to check what you are doing in your opening controller's life cycle methods.

1 Comment

Thanks for the response, I will cross check it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.