我正在尝试在UITableViewCell中打印UIImageView的框架,但我得到{{0,0},{0,0}}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:13.0f];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//cell.imageView.frame = CGRectMake(2, 2, 38, 38);
}
NSString *imageName = [[itemsArr objectAtIndex:indexPath.row] objectForKey:@"image"];
cell.imageView.image = [UIImage imageNamed:imageName];
cell.textLabel.text = [[itemsArr objectAtIndex:indexPath.row] objectForKey:@"title"];
NSLog(@"Image Frame : %@", NSStringFromCGRect([cell.imageView frame]));
return cell;
}
我做错了什么?
答案 0 :(得分:0)
试试这个,我在代码中添加了我的标记
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:13.0f];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//cell.imageView.frame = CGRectMake(2, 2, 38, 38);
}
NSString *imageName = [[itemsArr objectAtIndex:indexPath.row] objectForKey:@"image"];
cell.imageView.image = [UIImage imageNamed:imageName];
/* EDITED CODE START */
CGFloat x = cell.imageView.image.origin.x;
CGFloat y = cell.imageView.image.origin.y;
CGFloat width = cell.imageView.image.size.width;
CGFloat height = cell.imageView.image.size.height;
cell.imageView.frame = CGRectMake(x,y,width,height);
/* EDITED CODE END */
cell.textLabel.text = [[itemsArr objectAtIndex:indexPath.row] objectForKey:@"title"];
NSLog(@"Image Frame : %@", NSStringFromCGRect([cell.imageView frame]));
return cell;
}
答案 1 :(得分:0)
@implementation UITableViewCell (BrowseHistoryView) - (void)layoutSubviews { [super layoutSubviews]; if (isPhone) { self.imageView.frame = CGRectMake(5, 3, 18.0f, 18.0f); } else { self.imageView.frame = CGRectMake(10, 15, 18.0f, 18.0f); } } @end