iOS - UITableView滚动条离开屏幕

时间:2013-05-22 05:02:24

标签: iphone ios ios6 uitableview

我是iOS的新手,我有一些严重的问题,我不知道为什么会发生这种情况,我也试图找出原因,但我失败了。

我正在iPhone中创建一个应用程序使用twitter api获取特定用户的推文,我在获取json数据方面没有问题,也可以使用storyboard在iOS 6中的UITableView中显示它,我已将行高改为200 px,这样我就可以显示用户名文字推文和图片。

但是,当我向上或向下滚动UITableViewCell时,滚动条会离开屏幕。

可能是什么原因?我该如何解决?

ScreenShots

首先,当应用程序加载滚动条时,它会显示如下全屏

enter image description here


然后当我滚动它离开屏幕

enter image description here

最后它完全退出了屏幕

enter image description here

UITableView委托方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSMutableArray *name,*time,*tweet,*image;

    name=[[NSMutableArray alloc]init];
    time=[[NSMutableArray alloc]init];
    tweet=[[NSMutableArray alloc]init];
    image=[[NSMutableArray alloc]init];


    static NSString *CellIdentifier = @"SimpleTableItem";

    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];


    for (User *userModel in self.user) {
        [name addObject:userModel.nameStr];
        [image addObject:userModel.imageStr];

    }

    for (Json *jsonModel in self.json) {
        [tweet addObject:jsonModel.tweetStr];
        [time addObject:jsonModel.timeStr];


    }

    // Fetch using GCD
    dispatch_queue_t downloadThumbnailQueue = dispatch_queue_create("Get Photo Thumbnail", NULL);
    dispatch_async(downloadThumbnailQueue, ^{
        NSString *imageURL=[image objectAtIndex:indexPath.row];
        NSURL *url = [NSURL URLWithString:imageURL];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *img = [[UIImage alloc] initWithData:data];
        dispatch_async(dispatch_get_main_queue(), ^{

            UIImageView *image = (UIImageView *)[cell.contentView viewWithTag:5];
            image.image=img;

            [cell setNeedsLayout];
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            [spinner stopAnimating];

        });
    });

    self.labelName = (UILabel *)[cell.contentView viewWithTag:10];
    [self.labelName setText:[NSString stringWithFormat:@"%@", [name objectAtIndex:indexPath.row]]];


   self.labelTime = (UILabel *)[cell.contentView viewWithTag:11];
    [self.labelTime setText:[NSString stringWithFormat:@"%@", [time objectAtIndex:indexPath.row]]];




     self.labelTweet = (UILabel *)[cell.contentView viewWithTag:12];
    [self.labelTweet setText:[NSString stringWithFormat:@"%@", [tweet objectAtIndex:indexPath.row]]];


    cell.imageView.frame=CGRectMake(0, 0, 40, 40);
    cell.textLabel.lineBreakMode=NSLineBreakByWordWrapping;

    return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat rowHeight=self.labelName.frame.size.height+self.labelTime.frame.size.height+self.labelTweet.frame.size.height+50;
        return rowHeight;
}

3 个答案:

答案 0 :(得分:2)

滚动离开屏幕意味着tableView框架大于屏幕尺寸

使用setFrame:方法

正确设置tableview的框架

答案 1 :(得分:1)

我认为你必须检查UITableView的高度。显示屏幕截图。

答案 2 :(得分:0)

此处ScrollBar会降低,因为Height of TableView大于您在其中添加TableView的UIView。根据您的视图调整框架,然后ScrollBar不会消失。

相关问题