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

标题: ios - 添加 UISearchBar 后 UIRefreshControl 的行为有所不同 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 22:16
标题: ios - 添加 UISearchBar 后 UIRefreshControl 的行为有所不同

我在 iOS 7 中使用 UITableViewController 子类。

在我将搜索栏添加为表格 View 的 tableHearerView 之前,UIRefreshControl 按预期工作:我在 viewDidLoad 中触发了 beginRefreshing,每次进入此屏幕时我都可以看到它在旋转。

添加搜索栏后,当我进入此屏幕时,我看不到 UIRefreshControl 旋转。其他一切似乎都可以正常工作,例如下拉将显示旋转的 UIRefreshControl。

我是否以正确的方式使用了这 2 个小部件?如何解决此问题,以便我可以像添加搜索栏之前看到的那样看到旋转?

提前非常感谢!



Best Answer-推荐答案


看来手动调用beginRefreshing方法也需要手动设置tableView的偏移量。

这是 Objective-C 中的解决方案:

[self.tableView setContentOffset:CGPointMake(0, -self.refreshControl.frame.size.height) animated:YES];

这里是 Swift 中的解决方案:

self.tableView.setContentOffset(CGPointMake(0, -self.refreshControl!.frame.size.height), animated:true)

关于ios - 添加 UISearchBar 后 UIRefreshControl 的行为有所不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23635579/






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