我正在使用 pull to refresh 来刷新 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
}
}
}
除 iPhone X 外,在 iOS 设备和模拟器上一切正常。任何人都可以建议我做错了什么吗?
谢谢
最佳答案
您的应用仅适用于 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
为 false 时调用。
-(void)refreshAPI{
if ([APP_DELEGATE isNetAvailable]) {
[self fetchAPI];
}
[self.tableView.refreshControl endRefreshing]; //end refreshing
}
关于objective-c - iOS 拉动刷新不适用于 iPhone X 等特定设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50383237/