I am trying to dtermine the width of the cell that I'm in when i am creating my thumbnails (it's for an app very similar to the photos app on the iphone).
This is what I have:
- (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, photoWidt开发者_Go百科h, 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;
}
My main problem is with:
int photoWidth = self.frame.size.width / 4;
I cannot figure out the height and width of the Table Cell.
Any help would be appreciated, Cheers, Stefan
At this point the table cell which is in the making cannot know how big it will be, unless you tell it. It also has no reference to the tableview it will be added to, so there is no way.
You could just use some size, set the appropriate resizing masks and when adding the cell, determine the frame with dimensions from tableView.frame.size
.
精彩评论