2013-05-22 77 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不會消失。