2015-01-16 25 views
0

活动指示器启动,但在调用隐藏功能时不会停止。我试过把隐藏功能放在不同的地方,但它仍然不隐藏。隐藏活动指示器不起作用

隐藏活动的指标:Q0ViewController().hideActivityIndicator(self.view)

我使用的快捷实用功能在这里找到: 开始活动的指标查询后https://github.com/erangaeb/dev-notes/blob/master/swift/ViewControllerUtils.swift

override func viewDidLoad() { 
    super.viewDidLoad() 
    Q0ViewController().showActivityIndicator(self.view) 
    self.locationManager.delegate = self //location manager start 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest 
    self.locationManager.requestWhenInUseAuthorization() 
    self.locationManager.startUpdatingLocation() 
} 

隐藏活动的指标:

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { 
    CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: { (placemarks, error) -> Void in 
     if (error != nil) { 
      println("Error:" + error.localizedDescription) 
      //return 
     } 
     if placemarks.count > 0 { 
      let pm = placemarks[0] as CLPlacemark 
      self.displayLocationInfo(pm) 
      currentLoc = manager.location 
      currentLocGeoPoint = PFGeoPoint(location:currentLoc) 
      var query = PFQuery(className:"test10000") 
      query.whereKey("RestaurantLoc", nearGeoPoint:currentLocGeoPoint, withinMiles:100) //filter by miles 
      query.limit = 1000 //limit number of results 
      query.findObjectsInBackgroundWithBlock { 
       (objects: [AnyObject]!, error: NSError!) -> Void in 
       if objects != nil { 
        unfilteredRestaurantArray = objects 
        originalUnfilteredArray = objects 
        println(objects) 
       } else { 
        println("error: \(error)") 
       } 
      Q0ViewController().hideActivityIndicator(self.view) //HIDE 
      } 
     } else { 
      println("error: \(error)") 
     } 
    }) 
} 

这不是主队列的问题,因为dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), {()->() in不能解决问题。

回答

0

到约书亚建议类似,只是代替:

Q0ViewController().showActivityIndicator(self.view) 
and 
Q0ViewController().hideActivityIndicator(self.view) 

要:

self.showActivityIndicator(self.view) 
and 
self.hideActivityIndicator(self.view) 
1

看起来你每次都在创建一个“Q0ViewController”的新实例。

相反,我会建议以初期实例作为一个属性上你的类:

// As a variable on the class instance 
let myViewController = Q0ViewController() 

// Initially show the activity indicator 
self.myViewController.showActivityIndicator(self.view) 

// Hide the activity indicator 
self.myViewController.hideActivityIndicator(self.view) 

希望这有助于!

+0

谢谢,但我似乎得到一个错误与类的实例[画面](HTTP变量://i.imgur.com/E93Zt2r.png) – Onichan

+0

看起来像你非常接近。只需将'Q0ViewController()。'更改为'self.' – Onichan