2013-01-21 32 views
0

正在創建一個Rss提要應用程序。我需要展示說明(每個超過5000個字符)。能夠顯示我的應用程序中的所有提要,但我的問題,當我嘗試滾動UITableView滾動不順利,我相信我需要爲我的內容進行延遲加載,但對iPhone開發新來說。任何人都可以向我展示正確的方式。並根據內容大小設置正確的單元格大小。當TableCell的內容/文字很大時,UITableView滾動卡住了

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

    static NSString *simpleTableIdentifier = @"SimpleTableCell"; 

    SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 


    } 


    MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row]; 
    if (item) { 

     if(cell.gestureRecognizers.count==0){ 
      UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longSelection:)]; 
      longPress.minimumPressDuration=1.0; 
      [cell addGestureRecognizer:longPress]; 


     } 

     UIImageView *imageView=[[UIImageView alloc] initWithFrame:cell.frame]; 
     UIImage *image=[UIImage imageNamed:@"Background.png"]; 

     imageView.image=image; 
     cell.backgroundView=imageView; 
     [[cell textLabel] setBackgroundColor:[UIColor clearColor]]; 

     cell.textLabel.textAlignment=NSTextAlignmentRight; 
     cell.textLabel.text=item.content; 
     cell.textLabel.numberOfLines=0; 
     cell.textLabel.font=[UIFont systemFontOfSize:15.0]; 
     [cell.textLabel sizeToFit]; 


     } 

    return cell; 



} 

感謝

回答

0

您必須使用-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

像這樣:

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row]; 
    //make sure to add the font you're using 
    CGSize stringSize = [item.content sizeWithFont:[UIFont fontWithName:@"HelveticaNeue" size:14] 
            constrainedToSize:CGSizeMake(320, MAXFLOAT) 
             lineBreakMode:UILineBreakModeWordWrap]; 

    int rowHeight = stringSize.height; 

    return rowHeight; 
} 

將這個代碼:

UIImageView *imageView=[[UIImageView alloc] initWithFrame:cell.frame]; 
    UIImage *image=[UIImage imageNamed:@"Background.png"]; 

    imageView.image=image; 
    cell.backgroundView=imageView; 

裏面的位置,像這樣和刪除它來自它現在是(保持它有使你有新的imageviews創建每次滾動時間:

if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
     UIImageView *imageView=[[UIImageView alloc] initWithFrame:cell.frame]; 
     UIImage *image=[UIImage imageNamed:@"Background.png"]; 

     imageView.image=image; 
     cell.backgroundView=imageView; 

    } 
+0

現在小區的高度是確定的,但仍然因爲內容是太大的UITableView滾動不順暢。 – user1997951

+0

請檢查我的編輯 – shabbirv

+0

嗨shabazco,我認爲滾動不平滑,因爲內容/文字很大。我認爲圖像沒有問題。即使我刪除圖像仍然滾動不平滑,它需要很長的時間來加載新的表格單元格大內容。 – user1997951