ios - Swift UIPageViewController & UIActivityIndicatorView -
is aware of issue stopping uiactivityindicatorview (ai) / removing uiview has been added uipageviewcontroller?
i showing ai using:
override func viewwilllayoutsubviews() { actind.frame = cgrectmake(0,0, 80, 80) actind.center.x = self.view.center.x actind.center.y = self.view.center.y - 40 actind.hideswhenstopped = true actind.layer.cornerradius = 5 actind.alpha = 0.5 actind.backgroundcolor = uicolor.blackcolor() actind.activityindicatorviewstyle = uiactivityindicatorviewstyle.whitelarge self.view.addsubview(actind) actind.startanimating() // next line prints out details of each subview on page testing purposes listsubviews(self.view)
i also, testing purposes, adding blank uiview view using:
aview.frame = cgrectmake(0, 0, 200, 200) aview.backgroundcolor = uicolor.bluecolor() self.view.addsubview(aview) }
then send parse.com query using delegate advise uipageviewcontroller (e.g. view) when data ready. working fine , have tested data returns correctly, , expected method being called.
in method try stop uiactivityviewcontroller & try hide aview:
self.actind.stopanimating() aview.removefromsuperview()
this didn't work tried:
self.actind.removefromsuperview()
this didn't work either. tried search through subviews on current view using:
func populateboards(boards: [board]) { println(self.actind) // print line 1 var subviews = self.view.subviews v in subviews { if v.iskindofclass(uiactivityindicatorview) { println("yes, activity view indicator \(v)") // print line 2 v.stopanimating() v.removefromsuperview() } } self.boards = boards println("populated boards!") // print line 3 }
print line 1 outputs: >
print line 2 outputs: yes, activity view indicator >
print line 3 outputs: "populated boards!"
edit:
the uipageviewcontroller setup following code (in case helps):
func setupuipageview() { self.pageviewcontroller = uipageviewcontroller(transitionstyle: uipageviewcontrollertransitionstyle.scroll, navigationorientation: uipageviewcontrollernavigationorientation.horizontal, options: nil) self.pageviewcontroller.delegate = self self.pageviewcontroller.datasource = self var startvc = self.viewcontrolleratindex(0) viewcontroller var viewcontrollers:[viewcontroller] = [startvc] self.pageviewcontroller.setviewcontrollers(viewcontrollers, direction: .forward, animated: true, completion: nil) self.pageviewcontroller.view.frame = cgrectmake(0, 0, self.view.frame.width, self.view.frame.height) self.pageviewcontroller.view.alpha = 0.0 self.addchildviewcontroller(self.pageviewcontroller) self.view.addsubview(self.pageviewcontroller.view) self.pageviewcontroller.didmovetoparentviewcontroller(self) }
help! in advance :d
you should call ui related code on main queue. parse query async , completion block might called on different thread.
wrap call in block:
nsoperationqueue.mainqueue().addoperationwithblock { self.actind.stopanimating() }
Comments
Post a Comment