从iOS 13中出现模态时拉动以刷新表视图中的表格

问题描述 投票:2回答:2

我在tableview中使用了UIRefreshControl,它在ios 13中自动呈现了视图控制器。使用了同一视图控制器中的tableview。

vc.modalPresentationStyle = .automatic

问题是,只要刷新刷新,视图控制器就会立即关闭。我已阻止以下代码关闭,但视图控制器仍然无法从顶部刷新。

vc.isModalInPresentation = true

如何刷新表视图而不关闭视图控制器?

ios tableview modalviewcontroller ios13 uirefreshcontrol
2个回答
0
投票

解决方案是在显示视图控制器之前,使用可用的UITableView选项全屏显示包含UICollectionViewmodalPresentationStyle的视图控制器:

yourViewController.modalPresentationStyle = UIModalPresentationFullScreen;
yourViewController.modalPresentationStyle = .fullScreen

Objective-C中的完整示例:

NSString *storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
// YourViewController is the VC that contains a table view or collection view with a refresh control.
YourViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIdentifier"];
// Or not using storyboard
// YourViewController *vc = [YourViewController new];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:YES completion:nil];

使用其他modalPresentationStyle选项进行实验以满足您的需求。

Apple Docs中的更多信息。


0
投票

如果iOS版本是10以后的版本,请使用tableView的RefreshControl,不要使用addSubview。

let refreshControl:UIRefreshControl = UIRefreshControl.init()

if #available(iOS 10.0, *) {
   tableView.refreshControl = refreshControl
} else {
   tableView.addSubview(refreshControl)
}

无论isModalInPresentation是对还是错。

© www.soinside.com 2019 - 2024. All rights reserved.