ios - Swift: Programically Change a Storyboard's Class -
i developing game, , have been saving level design end. anyway, here , running issues. use same storyboard of levels, change class of storyboard different view controller. assuming having 50+ storyboards in project not thing, correct me if wrong.
right "sample" code have, give idea of want do.
let storyboard = uistoryboard(name: "main", bundle: nil) nextviewconroller = storyboard.instantiateviewcontrollerwithidentifier("levelstoryboard") storyboard.class = "level" + string(currentlevel) + "controller" //purely concept code - not work. presentviewcontroller(nextviewconroller, animated: true, completion: nil)
if have common ui has varying logic depending on condition, separate varying logic in many classes needed , merely use ib's view controller channel common user interface elements. view controller class specify in ib have iboutlets , ibactions plus variable appropriate instance of "logic" class. upon initialization, view controller have instantiate appropriate type logic class (a place use factory pattern) , link outlets object or merely act delegate.
Comments
Post a Comment