【发布时间】:2011-03-06 14:12:52
【问题描述】:
您好,
我正在尝试使用异步加载图像 (80px x 60px) 来实现 tableview。我有异步位工作,但是我的文本 (cell.textlabel.text) 没有正确显示 - 它与图像重叠!
这是我 iPhone 的照片:
关于如何解决此问题的任何想法?
我尝试使用 CGRectMake 设置框架,但它不起作用...这里完全没有想法,我想问问 stackoverflow 社区。p>
非常感谢,
这是我正在使用的代码: -(UITableViewCell ) tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
static NSString *CellIdentifier = @"ImageCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]
autorelease];
} else {
AsyncImageView* oldImage = (AsyncImageView*)
[cell.contentView viewWithTag:999];
[oldImage removeFromSuperview];
}
CGRect frame;
frame.size.width=80; frame.size.height=60;
frame.origin.x=0; frame.origin.y=0;
AsyncImageView* asyncImage = [[[AsyncImageView alloc]
initWithFrame:frame] autorelease];
asyncImage.tag = 999;
NSString *urlStr = [[NSString alloc] initWithFormat:@"http://www.example.com/driverPhotos/%@/%@_80.png",[options objectAtIndex:[indexPath row]],[images objectAtIndex:[indexPath row]]];
NSURL* url=[NSURL URLWithString:urlStr];
[asyncImage loadImageFromURL:url];
[cell.contentView addSubview:asyncImage];
cell.textLabel.frame=CGRectMake(100, 0, 220, 60);
cell.textLabel.text=@"Hi";
return cell;
}
【问题讨论】:
-
您是否尝试将图像设置为 cell.imageView.image 属性 insted addSubview?
-
@Mat He 正在使用自定义图像视图。
-
我正在使用子视图,因为我希望图像异步加载。
标签: iphone uitableview