【问题标题】:iOS Pull To Refresh Not Working on Specific Devices like iPhone XiOS 拉动刷新不适用于 iPhone X 等特定设备
【发布时间】:2018-10-27 05:41:57
【问题描述】:

我正在使用 pull 来刷新 tableview 上的常规数据刷新。

这是我的代码

-(void)addUIRefreshControl{

    //Instantiate and Configure Refresh Control

    self.refreshControl = [[UIRefreshControl alloc] init]; // initialize refresh control
    self.refreshControl.tintColor = [UIColor appBaseColor]; // set tint color
    [self.refreshControl addTarget:self
                            action:@selector(refreshAPI)
                  forControlEvents:UIControlEventValueChanged]; // add target

    [self.tableView addSubview:self.refreshControl]; // add the refresh control

}

-(void)refreshAPI{

    if ([APP_DELEGATE isNetAvailable]) {
        [self fetchAPI];
    }else{
        if (self.refreshControl) {
            [self.refreshControl endRefreshing]; //end refreshing
        }
    }
}

在 iOS 设备和模拟器上一切正常,除了 iPhone X。谁能指出我做错了什么?

谢谢

【问题讨论】:

  • 将 refreshcontrol 移动到 viewDidAppear 中的 superview

标签: objective-c iphone pull-to-refresh iphone-x uirefreshcontrol


【解决方案1】:

您的应用是否仅适用于 iOS 10 及更高版本?如果是这样,您应该使用注释掉的行:

- (void)addUIRefreshControl{
    UIRefreshControl * refreshControl = [[UIRefreshControl alloc] init]; // initialize refresh control
    refreshControl.tintColor = [UIColor appBaseColor]; // set tint color
    refreshControl addTarget:self
                      action:@selector(refreshAPI)
            forControlEvents:UIControlEventValueChanged]; // add target
    if (self.tableView != NULL) {
        // tableView will have a strong reference (and retain) refreshControl ; no need to have it be its own property
        self.tableView.refreshControl = refreshControl
    } else {
        NSLog(@"suprise!  self.tableView is null");
    }
}

当值更改(或更新)时,您应该始终调用“endRefreshing”。以前,您只有在 isNetAvailable 为假时才调用。

-(void)refreshAPI{

    if ([APP_DELEGATE isNetAvailable]) {
        [self fetchAPI];
    }

    [self.tableView.refreshControl endRefreshing]; //end refreshing
}

【讨论】:

  • 嗨 Micheal,我在我的 API 回调中调用 endRefreshing。
  • 您在原始问题中提供的示例代码中是否不包含 API 回调?
  • 不,Micheal,它在 fetchAPI 方法中。我也试过你的代码。但它仍然不适用于 iPhone X。它适用于其他设备。真的很奇怪
  • 如果你在 Xcode 中设置断点,refreshAPIfetchAPI 会被调用吗?你能在endRefreshing 处设置一个断点,它会在 iPhoneX 上命中吗?
  • 不,Micheal,选择器方法根本没有被调用。我一直将屏幕拖到一半,但它根本没有做任何事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多