如何滚动循环数据?

时间:2015-02-04 12:25:07

标签: objective-c

我需要实现的是能够向上和向下滑动以在所显示的记录之间滚动,因为在大约10条记录之后它现在变为屏幕外。

-(void)createInfo:(NSString *)dateField withField:(NSString *)setName withFieldKvMax:(NSString *)kvField withFieldMaMax:(NSString *)maField withFieldId:(int)idField withFieldIncrement98:(int)increment98 withFieldIncrement147:(int)increment147 withFieldIncrement118:(int)increment118
{

    UILabel *dateTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, increment98, 208, 21)];
    dateTimeLabel.text = [NSString stringWithFormat:@"%@", setName];
    dateTimeLabel.tag = idField;
    [_scrollView addSubview:dateTimeLabel];

    UILabel *infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, increment118, 331, 21)];
    infoLabel.text = [NSString stringWithFormat:@"Max mA: %@ Max kV: %@ %@", maField, kvField, dateField];
    [infoLabel setFont:[UIFont systemFontOfSize:11]];
    infoLabel.tag = idField;
    [_scrollView addSubview:infoLabel];

    UIProgressView *progBar = [[UIProgressView alloc]initWithFrame:CGRectMake(16, increment147, 343, 2)];
    progBar.tag = idField;
    [_scrollView addSubview:progBar];

    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [deleteButton addTarget:self
                     action:@selector(deleteInfo:)
           forControlEvents:UIControlEventTouchUpInside];
    [deleteButton setTitle:@"X" forState:UIControlStateNormal];
    [deleteButton setTintColor:[UIColor redColor]];
    deleteButton.frame = CGRectMake(329, increment98, 30, 30);
    deleteButton.tag = idField;
    [_scrollView addSubview:deleteButton];
}

因此,数据库每次迭代行都会添加到scrollview。但即使行超过scrollview的高度,我也无法使用scrollview滚动。

scrollview被委托给viewcontroller

不确定在哪里看,因为大多数答案只涉及(数据大于高度应滚动)

2 个答案:

答案 0 :(得分:0)

_scrollView.contentSize = CGSizeMake(373, 4000);

现在似乎有效。

答案 1 :(得分:0)

我认为你想要的是

_scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, newHeight);

newHeight将是您添加的对象的最后一个yPosistion加上它的高度。