【问题标题】:UITableViewCell's IamgeView frameUITableViewCell 的 IamgeView 框架
【发布时间】:2012-08-15 09:58:03
【问题描述】:

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

我做错了什么?

【问题讨论】:

    标签: uitableview uiimageview


    【解决方案1】:

    试试这个,我在你的代码中添加了我的标记

    - (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;
    }
    

    【讨论】:

    • 还是不行。我更正了以下 CGFloat x = cell.imageView.image.origin.x; CGFloat y = cell.imageView.image.origin.y;到 CGFloat x = cell.imageView.frame.origin.x; CGFloat y = cell.imageView.frame.origin.y;
    【解决方案2】:
    @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); } } @结尾

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      • 2012-08-07
      相关资源
      最近更新 更多