ios - Calling upon the previous view controller in Swift -
i trying call upon root controller , don't know code call upon it. i'm using conditional , check previous view controller was, , block of code run depending on was. here code:
secondviewcontroller
override func viewdidload ( ) { super.viewdidload ( ) let previouscontroller = storyboard!.instantiateviewcontrollerwithidentifier ("firstviewcontroller") as? firstviewcontroller //help in line below //if root view controller == previouscontroller { //run code //} }
let stack = self.navigationcontroller.viewcontrollers if (stack.count > 1) { let previouscontroller = stack[stack.count-2] }
or if don't have navigation controller
let previouscontroller = self.presentingviewcontroller
also, clear, root view controller first view controller in stack, i.e:
self.navigationcontroller.viewcontrollers.firstobject
or
var previouscontroller : uiviewcontroller = self var rootcontroller : uiviewcontroller? { var rootviewcontroller = previouscontroller var previouscontroller = rootviewcontroller.presentingviewcontroller } while (previouscontroller != nil)
Comments
Post a Comment