我有一个UITableView我尝试添加一个UIRefreshControl,但它从未显示我试过几件事
例如:
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
但无法看到UIRefreshControl
任何帮助将不胜感激
-------------------编辑--------------------
我终于找到了解决方案
在xib文件中,uitableview在scrollview部分我检查弹跳和垂直弹跳现在它的工作原理。谢谢你的帮助
答案 0 :(得分:0)
对于Objective-C:
您可以在tableView
内设置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
}
或强>
更好地实例化UITableViewController
,然后将UIRefreshControl
和UITableView
设置为,即:
UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = uitableViewAlert;
refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refreshTable:) forControlEvents:UIControlEventValueChanged];
[tableViewController setRefreshControl:refreshControl];
答案 1 :(得分:0)
希望可以帮到你
var refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(ViewController.refreshData),
forControlEvents: UIControlEvents.ValueChanged)
refreshControl.attributedTitle = NSAttributedString(string: "下拉刷新数据")
self.tableView?.addSubview(refreshControl)
答案 2 :(得分:0)
对于Refresh视图,我们只需在代码中执行此操作: -
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()
答案 3 :(得分:0)
UIRefreshControl仅使用UITableViewController实例100%正常工作。您可以在此处跟踪类似问题:UIRefreshControl without UITableViewController