2011-03-06 67 views
1

问候,UITableView:如何偏移单元格中的文本?

我想实现与异步加载图像(80px x 60px)的tableview。我有异步位工作,但是我的文本(cell.textlabel.text)没有正确显示 - 它与图像重叠!

这里是我的iPhone的照片:

text overlaps image...

,我怎么可能会解决这个任何想法?

我试着用CGRectMake设置一个框架,但它不工作......所有的想法都在这里,我想我会问stackoverflow社区。

很多感谢,

这里是我使用的代码: - (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); 
    [email protected]"Hi"; 

    return cell; 

}

+0

有你尝试设置图像cell.imageView.image财产insted的addSubview? – Mat 2011-03-06 14:23:55

+0

@Mat他正在使用自定义图像视图。 – 2011-03-06 14:28:41

+0

我使用子视图,因为我想图像加载异步。 – Eamorr 2011-03-06 14:29:01

回答

2

你不能更改任何默认子视图(detailTextLabel,textLabel,imageView等)的框架如果你真的想要,那么你将不得不继承UITableView的子类骑布局子视图..

我建议忽略cell.textLabel和创建自己的UILabel和您要添加的同样的方式你AsyncImageView(带标签等),将其添加到cell.contentView

如果您未在cell.textLabel上设置任何内容,则不会出现并掩盖您的AsyncImageView。 (但是,如果它确实只是把你的AsyncImageView带到前面)

顺便说一句,如果你同时按下主页按钮和锁定按钮,iPhone会为你截图并保存到相册中。你可以通过电子邮件将它发送给你自己并在PC上获取。

1

或者你可以有一个自定义单元格并实现X,Y在layoutSubviews

-(void) layoutSubviews 
{ 
    [super layoutSubviews]; 
    [[self textLabel] setFrame:CGRectMake(75,10,250,20)]; 
    [[self detailTextLabel] setFrame:CGRectMake(75,30,250,20)]; 
} 
相关问题