0

我正在尝试在 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;
}

我究竟做错了什么 ?

4

2 回答 2

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;
}
于 2012-08-15T10:12:31.783 回答
0
@implementation UITableViewCell (BrowseHistoryView)

- (void)layoutSubviews
{
    [超级布局子视图];

    如果(是电话)
    {
        self.imageView.frame = CGRectMake(5, 3, 18.0f, 18.0f);
    }
    别的
    {
        self.imageView.frame = CGRectMake(10, 15, 18.0f, 18.0f);
    }
}

@结尾
于 2013-01-05T10:14:29.993 回答