OGeek|极客世界-中国程序员成长平台

标题: ios - UITableView 在 "pull down to refresh"期间顶部有额外空间 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:20
标题: ios - UITableView 在 "pull down to refresh"期间顶部有额外空间

我的表格 View 有问题。 它的顶部有一个空间,如下所示: enter image description here

当我打开 TasksTableViewController 时,问题没有出现。但是当我像这样从 TaskTableVC 打开另一个 View Controller 时:

 FilterTasksTableViewController * fttvc = [self.storyboard instantiateViewControllerWithIdentifier"FilterTasksTableViewController"];
fttvc.delegate = self;
UINavigationController * navVC = [self.storyboard instantiateViewControllerWithIdentifier"opoverNavigationController"];
[navVC setViewControllers[fttvc]];
[self presentViewController:navVC animated:YES completion:nil];

回到TaskTableVC,问题就出现了。 当我“下拉刷新”时,它恢复正常。

在我的 TaskTableVC 代码中:

- (void)viewWillAppearBOOL)animated {
//other code
[self populate];
}

- (void)viewDidLoad {

 dispatch_async(dispatch_get_main_queue(), ^{

   self.refreshControl = [[UIRefreshControl alloc] init];

    self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString" "];

    [self.refreshControl addTarget:self actionselector(refresh) forControlEvents:UIControlEventValueChanged];

    [self setRefreshControl:self.refreshControl];

});

    [self populate];
}

- (void)populate {

TaskHandler *handler = [[TaskHandler alloc] initWithContext:_context];
NSArray *allTasks = [handler getAll];

_tasks = [self filterTasks:allTasks];

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey"startDate" ascending:NO];
NSArray *descriptors = [NSArray arrayWithObjects:descriptor, nil];
_tasks = [[NSMutableArray alloc] initWithArray:[_tasks sortedArrayUsingDescriptors:descriptors]];
dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
    [self.refreshControl endRefreshing];
});

}

我希望你能帮助我解决这个奇怪的问题。



Best Answer-推荐答案


我用代码解决了我的问题。 我认为 Refresh control 有问题,所以我将其移出 dispatch_aysnc(dispatch_get_main_queue() 并添加了 [self.tableview reloadData 。这解决了我的问题。谢谢大家的回答。

关于ios - UITableView 在 "pull down to refresh"期间顶部有额外空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33140880/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4