swift - iOS segue freeze for many seconds before showing new view -
in main view of app have table view , 2 prototype cells. have configured segues each cell using storyboard. in view controller override prepareforsegue pass information on selected cell destination view.
the destination view isn't particularly complex , doesn't require heavy processing load.
the problem
when tap on cell in main controller first time, destination view appears after long delay, 5 40 seconds.
edit #2: subsequent taps faster
note that:
- if tap on same cell again before destination view has appeared, triggers destination view appear immediately.
- as above, tapping on different cell results in view appearing data first cell.
- as above, tapping on different control (with no associated segues) triggers destination view appear immediately.
- subsequent "taps" manifest less delay.
- the time profiler - can see - shows absolutely nothing happening during many seconds of delay.
- i have tried different type of segues, made no difference
a few println's show following sequence of events occurs:
- in main view, prepareforsegue executed (no delays)
- then destination viewdidload executed (no delays)
- ... long delay ...
- the collection , table views in destination controller start invoking data source related methods fetch data controller.
- the view appears (with unwanted animation, btw, that's different problem)
from have read on topic, suspect problem potentially related of above operations happening in background thread.
any idea might doing wrong?
edit #1: added code
in main view controller segues have been link using story board (ctrl-drag 2 prototype cells destination view).
the code looks bit below:
override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { var assetindex = assetstable.indexpathforselectedrow()?.row println("prepare segue - start: \(assets[assetids[assetindex!]]!.name)") if let destination = segue.destinationviewcontroller as? assetthingslistviewcontroller { destination.bundlesrepository = bundlesrepository! destination.asset = assets[assetids[assetindex!]] } println("prepare segue - end") }
edit #3 have made sample project available on bitbucket
i checked project. , while couldn't find else, suspect it's problem threading.
i managed fix problem implementing delegate tableview
, present new controller in code:
func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { let destination = storyboard?.instantiateviewcontrollerwithidentifier("buildertoyslistviewcontroller") as! buildertoyslistviewcontroller destination.botsrepository = botsrepository! destination.builder = builders[builderids[indexpath.row]] dispatch_async(dispatch_get_main_queue(), { () -> void in self.presentviewcontroller(destination, animated: true) { () -> void in } }) }
notice have set view controller storyboard id: buildertoyslistviewcontroller
, set tableview delegate. don't forget remove segues.
at end dissmis view in new view controller use code:
@ibaction func backbutton(sender: anyobject) { dismissviewcontrolleranimated(true, completion: { () -> void in }) // performseguewithidentifier("seguetoysbybuilder", sender: nil) }
this allow close view instead of wrongly creating new one.
Comments
Post a Comment