我正在尝试设置一个可以在右上角有图像的 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 =”行,图像确实以横向显示......尽管它不会转移到最右边。
如果我在这里做错了什么,请告诉我。
提前感谢您的任何帮助。