【发布时间】:2015-01-13 19:57:27
【问题描述】:
我使用 addsubview 修改了一个子视图表格单元格以在右侧包含一个附加图像(除了左侧的那个)。在我在顶部添加了一个搜索栏之前,我让它工作得很好。不知何故,正确的图像停止显示。我尝试删除搜索栏,但无法显示图像。我有一种感觉,我无意中打错了字,或者以某种方式弄乱了代码。
方法如下。除了右侧的图像不再显示之外,它可以正常工作。如果有人能发现我的错误或提出问题所在,将不胜感激。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *protoCell = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:protoCell];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:protoCell];
}
// IDModel * item;
IDModel * item = nil;
// if no search
//item = [self.tableItems objectAtIndex:indexPath.row];
//following for search
if (tableView == self.searchDisplayController.searchResultsTableView) {
item = [searchResults objectAtIndex:indexPath.row];
} else {
item = [self.tableItems objectAtIndex:indexPath.row];
}
// Configure the cell...
cell.textLabel.text = item.name;
cell.detailTextLabel.text = item.sub;
cell.imageView.image = [UIImage imageNamed:item.pic];
//following crops and rounds image
//add image to right
UIImageView *rightimage;
rightimage = [[UIImageView alloc] initWithFrame:CGRectMake(225.0,0.0,80.0,45.0)];
rightimage.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
// rightimage.image = [UIImage imageNamed:@"pic.jpg"];
[cell.contentView addSubview:rightimage];
rightimage.image = [UIImage imageNamed:item.pic];
return cell;
}
提前感谢您的任何建议。
【问题讨论】:
标签: ios addsubview