的UITableView和UIRefreshControl不showen

问题描述:

我有一个UITableView我尝试添加UIRefreshControl,但它从来没有showen我试过几件事情的UITableView和UIRefreshControl不showen

例如:

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文件中,在scrollview中的uitableview部分我检查反弹和垂直反弹,现在它的工作原理。您的帮助

+0

你有没有试过UIScrollView + DXRefresh类? –

+0

不,我现在就看它 – tamtoum1987

+0

你有viewController,并且你已经把tableView对吗? –

感谢家伙的Objective-C:

可以设置为遵循tableViewViewController刷新控制器:

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

更好的方式来实例化一个UITableViewController ,然后将您的UIRefreshControlUITableView设置为,即:

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

    refreshControl = [[UIRefreshControl alloc] init]; 
    [refreshControl addTarget:self action:@selector(refreshTable:) forControlEvents:UIControlEventValueChanged]; 
    [tableViewController setRefreshControl:refreshControl]; 
+0

第一个解决方案是我做的swift同样的事情,第二个我不知道如何UITableViewController将showen我已经尝试但没有任何变化 – tamtoum1987

+0

我的问题是反弹和垂直反弹我检查现在它的工作。谢谢你的帮助 – tamtoum1987

希望能帮助你

var refreshControl = UIRefreshControl() 
refreshControl.addTarget(self, action: #selector(ViewController.refreshData), 
     forControlEvents: UIControlEvents.ValueChanged) 
refreshControl.attributedTitle = NSAttributedString(string: "下拉刷新数据") 
self.tableView?.addSubview(refreshControl) 
+0

我的问题是反弹和垂直反弹我检查,现在它的工作。谢谢你的帮助 – tamtoum1987

+0

欢迎来到stackoverflow :-)请看看[答案] – JimHawkins

+0

请编辑有更多的信息。仅限代码和“尝试这个”的答案是不鼓励的,因为它们不包含可搜索的内容,也不解释为什么有人应该“尝试这个”。 – abarisone

对于刷新视图,我们需要做的只是这件事情在我们的代码: -

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() 

UIRefreshControl正常工作100%,只有的UITableViewController的实例。你可以在这里跟踪类似的问题:UIRefreshControl without UITableViewController

+0

我的问题是反弹和垂直反弹我检查,现在它的工作。感谢您的帮助 – tamtoum1987

+0

很高兴帮助:-) –