ios - How to stop UIActivityIndicator after UISearchBar has finished in Swift -
so set up:
i'm have app set parse, , i'm using pfquerytableviewcontroller
. i've added uisearchbar
screen. have search set , working fine.
question: make bit more obvious user search being performed, want add uiactivityindicator
can see loading. beginignoringinteractionevents()
cannot use app until search complete.
i'm having issues how make uiactivityindicator
stop animating, , endignoringinteractionevents()
- can't work out place code:
spinningactivityindicator.stopanimating() uiapplication.sharedapplication().endignoringinteractionevents()
i have placed code uiactivityindicator
inside method func searchbarsearchbuttonclicked(searchbar: uisearchbar)
once click search on keyboard, spinner start.
but can place code stop animating , enable app again?
the code added uisearchbar follows:
func searchbartextdidbeginediting(searchbar: uisearchbar) { searchbar.showscancelbutton = true self.loadobjects() } func searchbartextdidendediting(searchbar: uisearchbar) { // dismiss keyboard searchbar.resignfirstresponder() // force reload of table data self.loadobjects() } func searchbarsearchbuttonclicked(searchbar: uisearchbar) { // dismiss keyboard searchbar.resignfirstresponder() spinningactivityindicator = uiactivityindicatorview(frame: cgrectmake(0, 0, 50, 50)) spinningactivityindicator.center = self.view.center spinningactivityindicator.hideswhenstopped = true spinningactivityindicator.activityindicatorviewstyle = uiactivityindicatorviewstyle.gray view.addsubview(spinningactivityindicator) spinningactivityindicator.startanimating() uiapplication.sharedapplication().beginignoringinteractionevents() searchbar.showscancelbutton = false // force reload of table data self.loadobjects() } func searchbarcancelbuttonclicked(searchbar: uisearchbar) { // clear search criteria searchbar.text = "" // dismiss keyboard searchbar.resignfirstresponder() // force reload of table data self.loadobjects() }
and in func queryfortable() -> pfquery
added:
if filmsearchbar.text != "" { query.wherekey("filmname", containsstring: filmsearchbar.text!) }
thanks in advance!
i checked through of documentation pfquerytableviewcontroller
, , there's method objectsdidload()
seems promising. so, try adding below queryfortable()
function:
override func objectsdidload(error: nserror?) { super.objectsdidload(error) // code here stop uiactivityindicator }
and add print("objectsdidload")
inside function see works.
Comments
Post a Comment