2013-05-22 78 views
1

我是iOS新手,我有一些严重的问题,我不知道为什么发生这种情况,我也试图找出背后的原因,但我失败了。iOS - UITableView滚动条走出屏幕

我正在iPhone上创建一个应用程序,使用twitter api发送特定用户的推文,我在获取json数据方面没有问题,也能够在iOS 6中使用storyboard显示它,我已经改变了行高到200像素,这样我就可以显示用户名文本推文和图像。

但是,当我向上或向下滚动UITableViewCell滚动条走出屏幕。

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

截图

首先,它表明这样当应用程序加载的滚动条采用全屏

enter image description here


然后当我把它的滚动离开屏幕的

enter image description here

最后它compl etely失控屏幕

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; 
} 
+1

你可以发布屏幕截图吗? – Venkat

+0

你可以发布一些代码我的朋友吗? – NiravPatel

+0

不能明白你的意思是滚动条走出屏幕 – Durgaprasad

回答

1

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

+0

感谢您的帮助。 – Arun

2

那么滚动熄灭屏幕指的tableView帧比使用setFrame:方法

+0

感谢您的帮助。 – Arun

0

这里ScrollBar适当屏幕尺寸

设置的tableview的框大变为Down为Height of TableView越大则您要添加TableView的UIView。根据您的视图调整框架,然后ScrollBar不会消失。