Table header title gets stuck when implementing pull to Refresh in Swift

I have a tabular view inside UIViewController. I applied UIRefreshControlto tableView. If I dragged the table up while the update controller wheel is spinning, the first header is stuck in the middle of the table. I can’t understand what’s wrong ...

Here is a screenshot of the problem:

enter image description here

Here is the code I used in viewDidLoad:

        refreshControl = UIRefreshControl()
        refreshControl.tintColor = UIColor.redColor()
        refreshControl.addTarget(self, action: "handleRefresh:", forControlEvents: UIControlEvents.ValueChanged)
        tableView.insertSubview(refreshControl, atIndex: 0)
        tableView.sendSubviewToBack(refreshControl)

And this is how I create the headers:

  func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        let header: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView //recast view as a UITableViewHeaderFooterView
        header.contentView.backgroundColor = UIColor(red: 59/255, green: 134/255, blue: 134/255, alpha: 1.0) //make the background color light blue
        header.textLabel.textColor = UIColor.whiteColor() //make the text white
        header.alpha = 0.5 //make the header transparent
    }

Thanks a lot!

+4
source share
2 answers

tableView.addSubview(refreshControl) . . , " X", , .

, ? ,

let headerCell = tableview.dequeueReusableCellWithIdentifier("HeaderCell") as! UITableViewCell

UIView,

let view : UIView = UIView(frame: headerCell.view.frame)
view.addSubview(headerCell.view)
return view

, , .

0

:

tableView.insertSubview(refreshControl, atIndex: 0)

/:

self.tableView.addSubview(self.refreshControl)

, HandleRefresh

refreshControl.endRefreshing()

. , , , ...

StoryBoard. , - i.e, .

+1

All Articles