【发布时间】:2012-08-09 11:43:11
【问题描述】:
我有一个 UITableView,其方法如下所示 cellForRowAtIndexPath,问题是 cellImage 仅在完全向上滚动(因此没有行可见)然后释放后才出现。奇怪的是,我在另一个类中有相同的代码用于单独的表格视图,并且图像看起来很好。有什么想法吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
}
[cell.textLabel setText:[items objectAtIndex:indexPath.row]];
[cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:15.0f]];
[cell.textLabel setTextColor:[UIColor whiteColor]];
[cell setBackgroundColor:[[UIColor alloc] initWithRed:117.0/255.0 green:118.0/255.0 blue:121.0/255.0 alpha:1.0]];
[self.tableView setBackgroundView:nil];
[self.tableView setBackgroundView:[[UIView alloc] init]];
[self.view setBackgroundColor:[[UIColor alloc] initWithRed:167.0/255.0 green:169.0/255.0 blue:172.0/255.0 alpha:1.0]];
UIImageView *cellImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"next@2x.png"]];
[cell addSubview:cellImage];
[cellImage setFrame:CGRectMake(0, 0, 26, 24)];
[cellImage setCenter:CGPointMake(cell.frame.size.width - 30, cell.frame.size.height/2)];
return cell;
}
【问题讨论】:
-
不是真正的问题相关,但为什么是:[self.tableView setBackgroundView:nil]; [self.tableView setBackgroundView:[[UIView alloc] init]]; [self.view setBackgroundColor:[[UIColor alloc] initWithRed:167.0/255.0 green:169.0/255.0 blue:172.0/255.0 alpha:1.0]];在您的 cellforrow 委托方法中?不建议去那里
-
为什么要将 cellImage 添加到单元格作为默认单元格有 imgView 你可以像这样使用 cell.imgView.image = yourImage
-
如果你想显示点击单元格然后使用单元格的附件来显示指示器并删除你的 imageView
-
@Totumus Maximus 出于某种原因,这是我找到的唯一一个添加代码的地方
-
使用 UITableView 已有的 imageView 属性。另外,在设置框架后直接设置中心确实没有意义。但是,这不会造成伤害,并且与您的问题无关。
标签: iphone ios ipad uitableview uiimageview