ios - UIScrollview 拉动刷新不起作用

标签 ios uiscrollview pull-to-refresh visual-format-language

  self.refreshControl = [[UIRefreshControl alloc]init];
    [self.objDiscussiontopic addSubview:self.refreshControl];
    [self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];

- (void)refreshTable {
    //TODO: refresh your data
    [self.refreshControl endRefreshing];
}

这是我用来在我的 ScrollView 中添加刷新 Controller 的代码。 但是当我下拉 ScrollView 时,刷新控件没有显示,目标方法也没有被调用,为什么?

我搜索了一段时间,但没有得到任何合适的答案。

还有一件事 scrollview 有像这样的 VFL 约束:

//Pin scrolview to Parent View
    [VFLConstraint allignSubViewViewHorizentallyWithSubView:self.objDiscussiontopic OverSuperView:[self view]];
    [VFLConstraint allignSubViewViewVerticallyWithSubView:self.objDiscussiontopic OverSuperView:[self view] WithTopPading:[CommonFunction convertIphone6ToIphone5:0] AndBotomPading:[CommonFunction convertIphone6ToIphone5:57]];


+ (void)allignSubViewViewHorizentallyWithSubView:(UIView *)subView OverSuperView:(UIView *)superView{

    NSDictionary *viewDict= NSDictionaryOfVariableBindings(subView);
    [superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[subView]|" options:0 metrics: 0 views:viewDict]];
}

+ (void)allignSubViewViewVerticallyWithSubView:(UIView *)subView OverSuperView:(UIView *)superView WithTopPading:(float)topPading AndBotomPading:(float)bottomPading{

    NSDictionary *viewDict= NSDictionaryOfVariableBindings(subView);
    NSDictionary *metrics=[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:topPading],@"topPading",[NSNumber numberWithFloat:bottomPading],@"bottomPading", nil];
    [superView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-topPading-[subView]-bottomPading-|" options:0 metrics: metrics views:viewDict]];
}

最佳答案

尝试: [self.scrollView insertSubview:self.refreshControl atIndex:0];

检查 contentSize 它可以小于帧大小,如果是这样使用这行代码: self.scrollView.alwaysBounceVertical = true

关于ios - UIScrollview 拉动刷新不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33493470/

相关文章:

ios - 如何重新加载 View Controller 以便 JSON 更新?

iphone - iOS rangeOfString 无法找到肯定存在的字符串

iOS swift : Unexpectedly found nil while unwrapping optional value

iphone - UIScrollView 自动调整内容大小?

ios - UIStoryBoard 和 UIPageViewController 和 initWithTransitionStyle

objective-c - iOS 6 AppStore 应用列表 UIScrollView 行为

ipad - 如何为 iPad 创建 YouTube 或 eBay 风格的界面?

Android ListView 拉动刷新和滑动列表项以显示按钮

iphone - 过度释放 View 时 EGOTableViewPullRefresh 崩溃

android - 如何禁用 "pull to refresh"操作并仅使用指示器?