UIScrollview拉动刷新不起作用

时间:2015-11-03 07:20:18

标签: 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];
}

这是我用来在滚动视图中添加刷新控制器的代码。 但是当我下拉滚动视图时,刷新控件没有显示,并且目标方法也没有被调用为什么?

我正在搜索这段时间,但没有得到任何正确答案。

另一件事情就是让VFL约束的scrollview像这样:

//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]];
}

2 个答案:

答案 0 :(得分:3)

尝试: subscription.Dispose();

检查contentSize它可以小于帧大小,如果是这样,请使用以下代码行: [self.scrollView insertSubview:self.refreshControl atIndex:0];

答案 1 :(得分:0)

我认为UIRefreshControl不适用于普通滚动视图。 Apple的文档特别提到UITableViews when talking about refresh control.

您可以查看第三方拉动刷新库以将其添加到UIScrollView

相关问题