2011-10-02 50 views
0

我想只有一個可以水平顯示從服務器接收的圖像的uitableview單元。但目前的問題是,我收到來自服務器的15張圖像,並且該單元僅顯示前6張圖像,並且不顯示其餘9張圖像。不過,我可以看到水平卷軸滾動到最後,因爲我已根據15幅圖像的大小製作了內容。以下是代碼(用於測試目的,我從資源文件夾中檢索圖像,而不是從服務器獲取)。UITableView單元不水平地拉伸圖像

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


static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
} 

    CGFloat imageXCordinate = 0.0; 
    int i =0; 
    for(i=0; i < 15; i++) 
    { 
      NSString *filePathForIconPhotoImage = [[NSBundle mainBundle] pathForResource:@"icon_photo" ofType:@"png"]; 
      UIImage *iconPhoto = [[UIImage alloc] initWithContentsOfFile:filePathForIconPhotoImage]; 

      UIImageView *vwIcon=[[UIImageView alloc] initWithFrame:CGRectMake(imageXCordinate,2,iconPhoto.size.width,iconPhoto.size.height) ] ; 
      vwIcon.image =iconPhoto; 

      [cell.contentView addSubview:vwIcon]; 
      [vwIcon release]; 
      [iconPhoto release]; 

      imageXCordinate = imageXCordinate + basePhoto.size.width; 

    } 

     [tableView setContentSize:CGSizeMake((basePhoto.size.width * i, tableView.frame.size.height)]; 
    } 

注:1。 我知道我可以使用一個UIScrollView代替,但仍希望使用UITableView的一些具體原因。 2.我以編程方式創建了一個UITableView,並將其放置在[self.view addSuvView:myTableView]中。

在此先感謝。

+0

到底爲什麼你需要一個表視圖?如果要在單元格內水平滾動,可以將UIScrollView添加到單元格。如果您想要在整個區域內水平滾動顯示圖像,UIScrollView是您完美的解決方案。有許多教程可用毛皮子視圖平鋪,如果您有大量的圖像顯示 –

+0

感謝您的回覆,您可以創建可重複使用的視圖(類似於出列單元格)。如果你可以指向我的教程有關重新使用scrollView加載和滾動顯示圖像,將不勝感激。 – Prazi

+0

如果您有蘋果開發者帳戶,則可以觀看wwdc 2010會話視頻(https://developer.apple.com/videos/wwdc/2010/)。您想要的會話被命名爲「使用滾動視圖設計應用程序」。 wwdc 2011(https://developer.apple.com/videos/wwdc/2011/)有一個後續會議「高級滾動視圖技術」 –

回答