我正在嘗試設置一個可以在右上角顯示圖像的UITableViewCell。爲什麼在旋轉到橫向時,此UIImage從UITableViewCell消失?
我讓它爲縱向模式工作,但是當我旋轉到橫向時,圖像消失。
下面的代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIImage *cornerImage = [UIImage imageNamed:@"star_corner.png"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(cell.contentView.bounds.size.width - cornerImage.size.width,
0,
cornerImage.size.width,
cornerImage.size.height)];
imageView.tag = kCornerImageViewTag;
[cell.contentView addSubview:imageView];
[imageView release];
}
UIImageView *theView = (UIImageView *)[cell.contentView viewWithTag:kCornerImageViewTag];
[theView setImage: [UIImage imageNamed:@"star_corner.png"]];
cell.textLabel.text = @"the text label";
return cell;
}
有趣的是,如果我註釋掉「cell.textLabel.text =」行,圖像不顯示在景觀...雖然它沒有轉移過來的最右邊。
如果還有什麼我在這裏做錯了,請讓我知道。
在此先感謝您的幫助。
感謝您的回覆。我實際上是響應didRotateFromInterfaceOrientation。 自從幾個月前發佈這個問題後,我發現簡單的解決方案只是添加: imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; 將圖像正確放置在橫向上。但是,由於調出單元格的「刪除」按鈕會導致圖像移動,所以它仍然不適用於我。 從做進一步的研究,似乎我需要子類UITableViewCell並做我的佈局 - 所以我正在探索如何做到這一點。 – 2010-08-18 17:12:16