ios - Delay when using instantiateViewControllerWithIdentifier but not performSegueWithIdentifier? -


the code below used push view controller onto navigation stack.

when using instantiateviewcontrollerwithidentifier, segue noticeably sluggish first time (~3 seconds) occurs reasonably fast each subsequent time. other posts suggested ensuring segue occurs on main thread, code accomplishes, didn't fix problem.

however, using performseguewithidentifier causes no delay.

the viewdidload code sendviewcontroller same first , subsequent pushes.

tried blanking out viewdidload destination view controller, still lag exists instantiateviewcontrollerwithidentifier not performseguewithidentifier.

how fix delay instantiateviewcontrollerwithidentifier?

no delay:

@ibaction func buttontapped(sender: uibutton) {     performseguewithidentifier(sendsegue, sender: self)   } 

results in delay when showing sendviewcontroller first time:

@ibaction func buttontapped(sender: uibutton) {     dispatch_async(dispatch_get_main_queue()) {         let vc = self.storyboard!.instantiateviewcontrollerwithidentifier(self.sendviewcontrollerid) as! sendviewcontroller         self.navigationcontroller!.pushviewcontroller(vc, animated: true)     }    } 

this issue occur in many different scenarios. best way determine causing specific problem profiling instruments included in xcode.

  1. click , hold build button in xcode window. see 4 options appear, select profile.
  2. once build runs window instruments pop up. select, time profiling options.
  3. a new window appear various metrics in it. top left corner have red record button. click red record button , launch app on phone.
  4. proceed transition giving problems. end recording after transition occurs selecting same button started recording with.
  5. review "details" pane in bottom left corner. see column titled "running time" shows time took execute every method in code (both os methods , user generated code)
  6. determine if out of place or occurs not intended. possibly go , execute transition again compare difference between two. clicking function in list take directly code being executed. can helpful.

it if transition takes 3-5 seconds 1 particular function obvious when following these steps. happy profiling!

wwdc last year has great segment on well. def worth checking out here: (open in safari only) wwdc profiling talk


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -