objective c - iOS Swift: UIPageViewController & API Calls in ContentViewControllers -
i've implemented uipageviewcontroller contains variable number of uiviewcontrollers each call api in viewdidload
method.
i'm having few problems due "known issue" of viewcontrollerbeforeviewcontroller
, viewcontrollerafterviewcontroller
data source methods being called twice. e.g when swiping right, next , 1 after next view controllers initialised. in turn means each initialised view controller's api calls made.
i want next view controller initialised , hence 1 api call made. had thought moving api call viewwillappear
although prefer if next view controller initialised.
is there way ensure data source methods called once?
thanks :)
func pageviewcontroller(pageviewcontroller: uipageviewcontroller, viewcontrollerafterviewcontroller viewcontroller: uiviewcontroller) -> uiviewcontroller? { let currentindex = self.pages.indexof(viewcontroller as! locationviewcontroller)! if currentindex == self.pages.count-1 { return nil } let nextindex = currentindex + 1 return self.pages[nextindex] } func pageviewcontroller(pageviewcontroller: uipageviewcontroller, viewcontrollerbeforeviewcontroller viewcontroller: uiviewcontroller) -> uiviewcontroller? { let currentindex = self.pages.indexof(viewcontroller as! locationviewcontroller)! if currentindex == 0 { return nil } let previousindex = currentindex - 1 return self.pages[previousindex] } func pageviewcontroller(pageviewcontroller: uipageviewcontroller, willtransitiontoviewcontrollers pendingviewcontrollers: [uiviewcontroller]) { self.pendingindex = self.pages.indexof(pendingviewcontrollers.first! as! locationviewcontroller) } func pageviewcontroller(pageviewcontroller: uipageviewcontroller, didfinishanimating finished: bool, previousviewcontrollers: [uiviewcontroller], transitioncompleted completed: bool) { if completed { self.currentindex = self.pendingindex if let index = self.currentindex { self.pagecontrol.currentpage = index } } }
Comments
Post a Comment