iOS UITableViewController 即使在顶部稍微滚动一下也会显示 UIRefreshControl

标签 ios objective-c iphone uitableview uirefreshcontrol

我的 UITableViewController TableView 出现意外问题。在 iOS 9.2 中测试

我在 Storyboard中为 UITableViewController 启用了“刷新”,并附加了它的 IBAction for valueChanged。请注意,tableview 具有使用“Plain”样式和自定义高度 45 的节标题。

问题是,通常您会期望将 tableview 拉下相当多,以触发刷新控件并开始旋转。

然而,在我的场景中,即使是一点点滚动也会使刷新控件出现并开始旋转。就像字面上的 2 厘米,这将使它出现。更奇怪的是,它会自动扩展高度,即使我什至没有将 tableview 拉到足以触发刷新。

另请注意,即使它开始完全旋转并自动结束旋转,但我在 IBAction 中为刷新控件链接的方法实际上还没有被触发。

例如,我正在缓慢向上滚动,当我即将到达顶部时,刷新控件将出现并将 tableview 向下移动,开始旋转,停止旋转。所有这一切都没有拉动 tableview 相当大的数量。

请注意,在我的代码中,根本没有“beginRefreshing”。此外,我没有任何“scrollViewDidScroll”或“scrollViewDidDrag”等方法来触发刷新控件。

我从来没有见过这种问题。由于其他原因,我无法将自定义 ViewController 与自定义 TableView 一起使用,因此需要解决此问题。

最佳答案

您可以通过编程方式添加 UIRefreshControl,它会正常工作。这是一个简单的示例,其中 UIRefreshControl 不是 IBOutlet(我没有包含 tableView 数据源方法):

#import "ViewController.h"

@interface ViewController () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) UIRefreshControl *refreshControl;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.refreshControl = [[UIRefreshControl alloc] init];
    self.refreshControl.backgroundColor = [UIColor lightGrayColor];
    [self.refreshControl addTarget:self action:@selector(actionRefresh:) forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview:self.refreshControl];
}

- (void)actionRefresh:(id)sender {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.refreshControl endRefreshing];
    });
}

// ...UITableView dataSource methods

@end

关于iOS UITableViewController 即使在顶部稍微滚动一下也会显示 UIRefreshControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35077011/

相关文章:

iphone - 带有 block 的UINavigationController动画过渡

iphone - 应用 3d 动画查看

ios - 如何在 Interface Builder 中将 Subview 添加到 UIButton

ios - 使用 UIWebView 进行基本身份验证

css - 使用 fx-layout ="column"的 Safari IOS 的 Flex 布局显示问题

检查浮点变量是否存在

objective-c - 如何从单元格的内容 View 中删除 subview ?

ios - RestKit CoreData 在单元测试期间挂起

ios - 如何在core graphics ios中连续绘制曲线

c - 从整数中获取浮点值