2011-08-04 39 views
0

我想在我的iPad應用程序中使用tableView來幫助顯示一個圖庫。 5幅圖像應以縱向模式顯示,8幅以橫向模式顯示。爲了實現這個功能,我做了以下工作。更改tableView造成的框架在我的應用程序中造成麻煩

1-心中已經採取了的tableView並旋轉90度

2-我再次旋轉了-90度的的tableView細胞,這樣我可以放置我的圖片它。

3我在我的TableView中放置了一些圖像並將其添加到我的scrollView中。

4 - 我有縱向和橫向設置爲我的tableView幀不同....

if(UIInterfaceOrientationIsPortrait(self.interfaceOrnetation)){ 
    myTableView.frame = CGRectMake(0,0,768,200); 

} 
else{ 
    myTableView.frame = CGRectMake(0,0,1024,200); 
} 

5 - 我也是不斷變化的,在didRotateFrominterfaceOrientation方法上面的行幀。

我用下面的代碼加載圖像中的tableView

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



if (cell==nil) { 
      NSLog(@"count "); 

      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewStylePlain reuseIdentifier:cellIdentifier] autorelease]; 

      UILabel *pageNumberLabel = [[UILabel alloc] init]; 
      pageNumberLabel.tag = 10; 

      pageNumberLabel.frame = CGRectMake(35, -10, 100, 50); 
      [cell.contentView addSubview:pageNumberLabel]; 

      UIImageView *thumbnailImageView = [[UIImageView alloc] init]; 
      thumbnailImageView.tag = 20; 
      thumbnailImageView.frame = CGRectMake(10, 35, 140, 160); 
      [cell.contentView addSubview:thumbnailImageView]; 

     } 
     id<PageDataSource> pd = [kbDataSource pageAtIndex:indexPath.row]; 

     UILabel *pageLabel = [cell viewWithTag:10]; 
     pageLabel.backgroundColor = [UIColor clearColor]; 
     pageLabel.text = [NSString stringWithFormat:@"Page %d",indexPath.row+1]; 
     pageLabel.textColor = [UIColor whiteColor]; 

     UIImageView *thumbnail = [cell viewWithTag:20]; 
     thumbnail.image = [pd thumbnailImageForPageNumber:indexPath.row+1]; 

     cell.selectionStyle = UITableViewCellSelectionStyleGray; 
     cell.transform = CGAffineTransformMakeRotation(M_PI/2); 
     return cell; 
    } 

的框架工作得很好首次。但是,當我旋轉設備,tableView中的圖像沒有得到顯示。我不知道問題出在哪裏..再次,如果我不改變旋轉後的框架,它工作正常,所有的圖像越來越顯示...有我在tableView中缺少的東西?

+0

不要做任何事情,並嘗試!因爲ipad會自動設置其桌面視圖 – Ganesh

+0

您還可以在方向功能中設置圖像視圖或滾動視圖。 – ram

+0

@ganesh:我不認爲iPad會在這裏做任何事......你需要設置tableView的高度,以便可見單元格的數量可以增加 –

回答

1

這聽起來像你的圖像定位是關閉的。圖像的x和y位置是什麼?我想你會發現你的圖像在旋轉時不在包含視圖框架內,因此你看不到它們。

但是,你說你要添加一個tableview到scrollview?你不應該這樣做。

+0

你似乎是正確的......我會檢查這一個。但是,你能告訴我爲什麼我不應該在我的scrollView上添加tableView嗎? Thanku .. +1你的回答.... –

+0

我也用一些代碼片段編輯了我的問題..請看看那個... –

+0

UITableView是UIScrollView的子類。 – ader