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.
- click , hold build button in xcode window. see 4 options appear, select profile.
- once build runs window instruments pop up. select, time profiling options.
- a new window appear various metrics in it. top left corner have red record button. click red record button , launch app on phone.
- proceed transition giving problems. end recording after transition occurs selecting same button started recording with.
- 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)
- 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
Post a Comment