【问题标题】:refresh controller for embedded tableview ios 6嵌入式tableview ios 6的刷新控制器
【发布时间】:2013-03-29 20:28:37
【问题描述】:

您好,我目前在 UIViewController 中嵌入了 tableview。在表格视图中,我收集了 json 数据。我希望制作一个刷新控制器,因此每当用户下拉时,都会刷新 json 数据。

我试过下面的代码

- (void)viewDidLoad
{
[superviewDidLoad];

UIRefreshControl *refreshControl = [[UIRefreshControl alloc]
init];
[refreshControl addTarget:nil action:@selector(updateArray) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;

}

-(void) updateArray{
[self.tableView reloadData];
[self.refreshControl endRefreshing];
}

我收到一条错误消息,提示在 ViewController 中找不到属性 refreshControl。

是因为我使用的是嵌入式 tableview 还是我做错了什么?

【问题讨论】:

  • 此代码是否在您的UIViewController 或其他地方?
  • 代码在UIViewController中
  • 看起来刷新控制处理需要在 UITableViewController 中,而不是在 UIViewController 中。看看,也许,this tutorial
  • 我已经看过那个教程,我知道你需要 UITableViewController,所以我想知道是否有办法解决这个问题?因为我需要刷新 UIViewController 中的 tableview。
  • 我使用EGOTableViewPullRefresh 在 iOS 5 中实现了拉动刷新。

标签: iphone ios6 xcode4.5 tableview uirefreshcontrol


【解决方案1】:

您正在 viewDidLoad 方法中实例化 UIRefreshControl。 updateArray 方法看不到对该对象的引用。您需要将其设为属性或实例变量。

@property (strong, nonatomic) UIRefreshControl *refreshControl;

然后代替

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];

使用

refreshControl = [[UIRefreshControl alloc] init];

【讨论】:

  • 如果您仍然遇到问题,您将不得不发布代码的更多详细信息。也许尝试将您的 addTarget: 方法更改为 self 而不是 nil。
【解决方案2】:

您只能将 UIRefreshControl 添加到 UITableViewController 而不能添加到 UIViewController。 检查此答案以在 UIViewController 中使用 UIRefreshControl ,其中 UITableViewController 是子级。 https://stackoverflow.com/a/14148118/1017099

【讨论】:

    猜你喜欢
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 2012-10-04
    • 2017-04-26
    • 2022-01-12
    • 1970-01-01
    • 2015-10-13
    相关资源
    最近更新 更多