0

I have a UITableView i try to add a UIRefreshControl but it's never showen i tried several things

For example :

    refreshControl = UIRefreshControl()
    refreshControl.attributedTitle = NSAttributedString(string: "")
    refreshControl.addTarget(self, action:    #selector(EvenementsViewController.refresh(_:)), forControlEvents:    UIControlEvents.ValueChanged)
    uitableViewAlert!.addSubview(refreshControl) // not required when using UITableViewController
    uitableViewAlert!.alwaysBounceVertical = true

but can't see the UIRefreshControl

any help will be appreciated

-------------------Edit --------------------

I finally just find the solution

in xib file, uitableview in scrollview part i check bounces and bounce vertically and now it works. thanks guys for your help

tamtoum1987
  • 1,957
  • 3
  • 27
  • 56

4 Answers4

0

For Objective-C :

you can set refresh controller as follow for tableView inside ViewController:

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc]init];
    [uitableViewAlert addSubview:refreshControl];
    [refreshControl addTarget:self action:@selector(refreshTable:) forControlEvents:UIControlEventValueChanged];

//Action : 

-(IBAction)refreshTable:(id)sender
{
   //do the refresh task
}

OR

Better way to instantiate a UITableViewController, and then setting your UIRefreshControl and UITableView to that, i.e.:

    UITableViewController *tableViewController = [[UITableViewController alloc] init];
    tableViewController.tableView = uitableViewAlert;

    refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(refreshTable:) forControlEvents:UIControlEventValueChanged];
    [tableViewController setRefreshControl:refreshControl];
Piyush
  • 1,534
  • 12
  • 32
  • the first solution is the same thing that i do in swift, the second one i dont undestand how UITableViewController will be showen i already try it but nothing change – tamtoum1987 Aug 31 '16 at 09:08
  • my problem was bounce and bounce vertically i checked that and now it works. thanks for your help – tamtoum1987 Aug 31 '16 at 09:23
0

Hope can help you

 var refreshControl = UIRefreshControl()
 refreshControl.addTarget(self, action: #selector(ViewController.refreshData),
        forControlEvents: UIControlEvents.ValueChanged)
 refreshControl.attributedTitle = NSAttributedString(string: "下拉刷新数据")
 self.tableView?.addSubview(refreshControl)
  • my problem was bounce and bounce vertically i checked that and now it works. thanks for your help – tamtoum1987 Aug 31 '16 at 09:23
  • Welcome to stackoverflow :-) please look at [answer] – JimHawkins Aug 31 '16 at 09:34
  • Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this". – abarisone Aug 31 '16 at 12:29
0

For Refresh view we need to do only this thing in our code:-

 let refreshControl = UIRefreshControl()

//MARK:- Life Cycle
override func viewDidLoad() {
    super.viewDidLoad()
 refreshControl.addTarget(self, action: #selector(NotificationVC.getlistPromotion), forControlEvents: UIControlEvents.ValueChanged)
 refreshControl.tintColor = UIColor.purpleColor()
 refreshControl.attributedTitle = NSAttributedString(string: "Refresh...")
 tableView.addSubview(refreshControl)
}

internal func getlistPromotion(){
//Do something here for Refresh table data
}

//and Finally for stop need to do
 self.refreshControl.endRefreshing()
Anand Nimje
  • 6,163
  • 4
  • 24
  • 43
0

UIRefreshControl works 100% properly with instance of UITableViewController only. You can track similar issue here: UIRefreshControl without UITableViewController

Community
  • 1
  • 1
O.G.O
  • 149
  • 1
  • 9