title: Cannot Hide Activity indicator at end of API call
body: <p>I have a table view where the data is loaded from an API call. I am displayed a <strong>Loading Overlay View</strong>. I used the following code to set up the loading overall view.</p>
  
  <p><a href="https://coderwall.com/p/su1t1a/ios-customized-activity-indicator-with-swift" rel="nofollow">https://coderwall.com/p/su1t1a/ios-customized-activity-indicator-with-swift</a></p>
  
  <p>But the issue is that I can't seem to hide the overlay view or activity indicator once the table view has been loaded. It just keeps on loading.</p>
  
  <p><strong><em>To start the activity indicator the following code is used:</em></strong></p>
  
  <pre><code> ViewControllerUtils().showActivityIndicator(self.view)
  </code></pre>
  
  <p><strong><em>To Stop it:</em></strong></p>
  
  <pre><code> ViewControllerUtils().hideActivityIndicator(self.view)
  </code></pre>
  
  <p>My API call code is below:</p>
  
  <pre><code> import UIKit
  
   class BioListTableViewController: UITableViewController {
  
  // variable to hold the index value of the cell tapped
  var cellTapped = Int()
  
  
  @IBOutlet var tableview: UITableView!
  
  var bioArray = NSArray(){
      didSet{
  
          dispatch_async(dispatch_get_main_queue()){
                 self.tableview.reloadData()
              }}}
  
  
  override func viewDidLoad()
  {
      super.viewDidLoad()
      self.tableView.rowHeight = 80.0
  
  
  
      // A switch Statement to check which cell was tapped and which API link to call
      switch cellTapped
      {
  
         case 0:
           test()
         case 1:
           test()
         default:
           test()
  
      }
  
     }
  
  override func viewDidAppear(animated: Bool)
  {
      ViewControllerUtils().hideActivityIndicator(self.view)
  }
  
  func test() {
  
  
       ViewControllerUtils().showActivityIndicator(self.view)
      println("This is TWEST")
  
      var request = NSMutableURLRequest(URL: NSURL(string: "APILink")!)
      var session = NSURLSession.sharedSession()
      request.HTTPMethod = "GET"
      UIApplication.sharedApplication().networkActivityIndicatorVisible = true
  
  
      var err: NSError?
  
      request.addValue("application/json", forHTTPHeaderField: "Content-Type")
      request.addValue("application/json", forHTTPHeaderField: "Accept")
  
      var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -&gt; Void in
      println("Response: \(response)")
      var strData = NSString(data: data, encoding: NSUTF8StringEncoding)
      println("Body: \(strData)")
      var err: NSError?
      var json = NSJSONSerialization.JSONObjectWithData(data, options: .MutableLeaves, error: &amp;err) as? NSArray
  
      UIApplication.sharedApplication().networkActivityIndicatorVisible = true
  
  
      // Did the JSONObjectWithData constructor return an error? If so, log the error to the console
      if(err != nil) {
  
      println(err!.localizedDescription)
      let jsonStr = NSString(data: data, encoding: NSUTF8StringEncoding)
      println("Error could not parse JSON: '\(jsonStr)'")
  
      dispatch_async(dispatch_get_main_queue()) {
  
      var alert = UIAlertController(title: "Alert", message: "Seems to be an error with server. Try Again Later", preferredStyle: UIAlertControllerStyle.Alert)
      alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
      self.presentViewController(alert, animated: true, completion: nil)
  
      }}
      else {
  
      UIApplication.sharedApplication().networkActivityIndicatorVisible = false
          //To to long tasks
         // LoadingOverlay.shared.hideOverlayView()
      // The JSONObjectWithData constructor didn't return an error. But, we should still
      // check and make sure that json has a value using optional binding.
      //var newWeather = WeatherSummary(id:"")
  
      if let parseJSON = json {
  
  
      self.bioArray = parseJSON
  
      }
      else {
      // Woa, okay the json object was nil, something went worng. Maybe the server isn't running?
      let jsonStr = NSString(data: data, encoding: NSUTF8StringEncoding)
      println("Error could not parse JSON: \(jsonStr)")
  
      }}
  
      })
  
      task.resume()
  }
  
  func testTwo(){
  
      println("THIS IS TEST 2")
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  // MARK: - Table view data source
  
  override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      // #warning Potentially incomplete method implementation.
      // Return the number of sections.
      return 1
  }
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      // #warning Incomplete method implementation.
      // Return the number of rows in the section.
      return self.bioArray.count ?? 0
  }
  
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCellWithIdentifier("bioCell", forIndexPath: indexPath) as! UITableViewCell
  
      // Configure the cell...
  
      let weatherSummary: AnyObject = bioArray[indexPath.row]
  
      if let id = weatherSummary["employeeName"] as? String
      {
          cell.textLabel?.text = id
  
      }
  
      if let job = weatherSummary["sector"] as? String {
          cell.detailTextLabel?.text = job
  
      }
  
      var fram = cell.imageView?.frame
      //fram? = CGRectMake( 0, 0, 50, 55 )
      let imageSize = 50 as CGFloat
      fram?.size.height = imageSize
      fram?.size.width = imageSize
      cell.imageView!.frame = fram!
      cell.imageView!.layer.cornerRadius = imageSize / 2.0
      cell.imageView!.clipsToBounds = true
      //cell.imageView?.image = UIImage(named: "userIcon.png")
  
      if let userImage = weatherSummary["userImage"] as? String{
          if   let url = NSURL(string: userImage){
              if let data = NSData(contentsOfURL: url){
                  if let image:UIImage = UIImage(data: data){
                      cell.imageView?.image = image
                  }
  
              }
          }
  
      }
  
  
      return cell
  }
  </code></pre>