-1

I am working on app where I using swift 4. But when I want to go from first viewcontroller to second viewcontroller I got this error

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 0]'

I tried to go from first viewcontroller to second viewcontroller on button click using like bellow

let vc = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
self.presentViewController(vc, animated:true, completion:nil)

But when I clicked button my app get crashed and get above nsrangeexception error

So how do I solve this error any other solution to go from first vc to second vc?

Ivan Smetanin
  • 1,884
  • 2
  • 17
  • 28
mab
  • 195
  • 2
  • 9
  • Can you provide the stacktrace of the crash? – Charles Srstka Apr 29 '18 at 05:39
  • What is the parent class of `NextViewController` – BallpointBen Apr 29 '18 at 05:44
  • @CharlesSrstka sorry i am new in swift 4 so i got only this error and my app is going to crash. – mab Apr 29 '18 at 05:52
  • @BallpointBen Yes UIViewController – mab Apr 29 '18 at 05:54
  • can you share `NextViewController` code? – Kamran Apr 29 '18 at 05:59
  • @Kamran sorry but i used gif animation and label which change text what i passed some value from my previous viewcontroller but now i am not passing anything any string so is that any problem because when i try to another viewcontroller to go their with some label value it is possible to go that viewcontroller – mab Apr 29 '18 at 06:04
  • 1
    @mab When the app crashes, get the backtrace and add it to your answer. Without more information it is not possible even to know what is actually crashing. – Charles Srstka Apr 29 '18 at 06:25
  • Your code shouldn't crash. I think that the issue is on the code of `NextViewController`. You have an `Array` there? You might do in it a "indexOfObject" search, and since you don't check if it's found (the high number should be a NSNotFound), you crash. Show the code of `NextViewController` or at least the full error message in the console. – Larme Apr 29 '18 at 09:29

2 Answers2

0

First of all check that your NextViewController has Storyboard ID in the storyboard:

enter image description here

And check that you're loading storyboard correctly:

let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
Ivan Smetanin
  • 1,884
  • 2
  • 17
  • 28
0

If you want to navigate through Controller on StoryBoard with Identifier "nextView", then do this(this will applicable when you are trying to show one storyboard's ViewController to another storyboard ViewController):

   let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
   let vc = storyBoard.instantiateViewController(withIdentifier: "nextView") as! NextViewController
   self.present(vc, animated:true, completion:nil)

OR If you are in same storyBoard then you can simply do this - Take a button in your firstVC and ctrl+ drag a segue upto your secondVC. Then click on the segue. (the round thing on between two view controller). -

enter image description here

And set a identifier for that (here about is the identifier, you can give any name for this)-

enter image description here

Here is the code -

@IBAction func UserDetailVC(sender: AnyObject) {
        self.performSegue(withIdentifier: "segueIdentifierName(about)", sender: sender)
    }
Md Rashed Pervez
  • 1,986
  • 8
  • 22