从iOS 13中的呈现模式中拉动以刷新tableview

时间:2019-09-29 16:45:20

标签: ios tableview modalviewcontroller ios13 uirefreshcontrol

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

vc.modalPresentationStyle = .automatic

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

vc.isModalInPresentation = true

如何在不关闭视图控制器的情况下刷新表格视图?

2 个答案:

答案 0 :(得分:2)

如果iOS版本晚于10,请使用tableView的RefreshControl,不要使用addSubview。

ng g s services/bram --module app

无论ModalInPresentation是对还是错。

答案 1 :(得分: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中的更多信息。

相关问题