【问题标题】:How to end UIRefreshControl without UITableViewController如何在没有 UITableViewController 的情况下结束 UIRefreshControl
【发布时间】:2013-04-03 14:07:58
【问题描述】:

我创建了一个没有 TableViewController 的 UIRefreshcontrol。我的问题是我将如何在另一种方法中结束它? 这就是我创建它的方式;

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

【问题讨论】:

标签: iphone ios uiviewcontroller uirefreshcontrol


【解决方案1】:

在@Justin Paulsson 的帮助下,我发现这是可以做到的;

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

-

-(void) handleRefresh:(UIRefreshControl *)controller
    {
        //Refresh code
        controller.endRefreshing;
    }

【讨论】:

    【解决方案2】:

    记录的方式是使用UITableViewController。其他任何东西都可以工作,但由于没有记录,它可能会在下一个 iOS 版本中中断。

    在你的情况下,我只使用UITableViewController

    【讨论】:

    • 是的,我知道这是一种首选方式,但我该怎么做呢?我宁愿保持这种状态,并以某种方式结束它。
    • 要继续使用您尝试的方式,您需要将refreshControl 的引用存储在属性或ivar 中,以便稍后使用它来调用endRefreshing
    • 或者只使用[controller endRefreshing],因为handleRefresh: 传递了对UIRefreshControl 的引用
    • 当然。我还没有看到它传递给handleRefresh:
    【解决方案3】:

    事实证明,UIRefreshControl 根本不需要 UITableView。 refreshControlproperty of UIScrollView。你可以在继承自 UIScrollView 的任何东西上设置它,当然包括 UITableView,也包括其他类,例如 UICollectionView。

    【讨论】:

      猜你喜欢
      • 2012-09-11
      • 2012-02-07
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 2022-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多