ios - Dismissing ViewController Scenario -


i new swift programming. stuck in 1 scenario. when app loads, first screen gets in viewcontroller1 user's latitude , longitude , gets data backend api , loads data in table view controller. code of getting user's location , loading table view controller in viewdidload method. in viewcontroller1, have button when tapped, presenting view controller (which embedded in navigation controller) modally. following lines of code using present new viewcontroller (viewcontroller2).

let vc2 = self.storyboard?.instantiateviewcontrollerwithidentifier("newvc2") as! newvc2             let navcontroller = uinavigationcontroller(rootviewcontroller: vc2)             vc2.delegate = self             self.presentviewcontroller(navcontroller, animated: true, completion: nil) 

when close viewcontroller2 saying self.dismissviewcontroller, closes , when control comes viewcontroller1, viewdidload executed again , code of invoking backend api , getting user's location getting invoked. so, passing data viewcontroller2 on dismissing it, used delegate pattern. created protocol , defined method in protocol.

protocol viewcontrollercloseddelegate {     func isviewcontrollerclosed(closed: bool); }  defined object of delegate in viewcontroller2. var delegate: viewcontrollercloseddelegate! = nil 

and added following code while dismissing viewcontroller2.

delegate.isviewcontrollerclosed(true) self.dismissviewcontrolleranimated(true, completion: nil) 

made viewcontroller1 implement viewcontrollercloseddelegate , added following function.

func isviewcontrollerclosed(closed: bool) {         self.isfromclosedvc = closed         print(isfromclosedvc)     } 

isfromclosedvc global variable defined viewcontroller1.

the value printing correctly (true in case) being passed viewcontroller2 when dismissed when try print in viewdidload, being printed false. thought of getting value viewcontroller2, , if true, not execute code users location , data backend api.

basically, trying user's location , getting data backend api once , update table view on swipe refresh. how achieve this? please help.

thank you. raj


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -