2011-01-09 76 views
0

我试图确定我在创建缩略图时的单元格宽度(这是一个非常类似于iphone上的照片应用程序的应用程序)。确定UITableViewCell的大小

这是我有:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 
int photoWidth = self.frame.size.width/4; 
    thumbnail1 = [[ThumbnailButton alloc] initWithFrame:CGRectMake(0, 0, photoWidth, 40) ]; 
    thumbnail2 = [[ThumbnailButton alloc] initWithFrame:CGRectMake(photoWidth, 0, photoWidth, 40) ]; 
    thumbnail3 = [[ThumbnailButton alloc] initWithFrame:CGRectMake(photoWidth * 2, 0, photoWidth, 40) ]; 
    thumbnail4 = [[ThumbnailButton alloc] initWithFrame:CGRectMake(photoWidth * 3, 0, photoWidth, 40) ]; 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     [self.contentView addSubview:thumbnail1]; 
     [self.contentView addSubview:thumbnail2]; 
     [self.contentView addSubview:thumbnail3]; 
     [self.contentView addSubview:thumbnail4]; 
    } 
    return self; 
} 

我的主要问题是:

int photoWidth = self.frame.size.width/4; 

我想不通的表格单元格的宽度和高度。

任何帮助,将不胜感激, 干杯, 斯特凡

+1

真的不是你的问题,但有一些内存泄漏在这里。将`[... autorelease]`添加到所有`alloc`语句中。 – mvds 2011-01-09 00:47:31

+0

谢谢你接受!我还是相当新的Objective-C – 2011-01-09 00:50:54

回答

1

此时表格单元格这是在制造不知道它会多大,除非你告诉它。它也没有提及它将被添加到的tableview,所以没有办法。

您可以使用一些尺寸,设置适当的调整大小掩码,并添加单元格时,确定尺寸从tableView.frame.size的框架。