UIImageView不会出现在动态创建的自定义UITableViewCell中

时间:2014-04-30 13:19:38

标签: ios objective-c uitableview uiimageview

我正在尝试整合MSSlidingPanelController而我遇到了问题。我希望自定义UITableViewCell包含图片和文字标签。 我TableViewItem继承了UITableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        // Initialization code
        self.textLabel.font = [UIFont fontWithName:FONT_OPENSANS_BOLD size:15];
        [self.imageView addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"corners"]]];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

    self.imageView.frame = CGRectMake(45.0f, 30.0f, 16.0f, 16.0f);
    self.textLabel.frame = CGRectMake(70.0f, 40, 240.0f, 20);
}

+ (TableViewItem *) tableViewItemWithUncheckableName:(NSString *)name
                          withLeftsideImageFromUrl:(NSString *)url
{
    TableViewItem   *item;

    NSParameterAssert(name);

    item = [[TableViewItem alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:g_LMVCCellIdentifier];
    [[item textLabel] setText:name];
    dispatch_async(dispatch_get_global_queue(0,0), ^{
        NSData * data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
        if ( data != nil )
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                // WARNING: is the cell still using the same data by this point??
                [[item imageView] setImage:[UIImage imageWithData: data]];
            });
        }
    });

    return (item);
}

我在这里使用它:

- (TableViewSection *) fillingSectionUserInfo
{
    TableViewItem *userInfoItem;
    TableViewSection *section;

    UserLogic * userLogic = [UserLogic instance];
    NSString * userName = [NSString stringWithFormat:@"%@ %@", [[userLogic currentUser] stringForKey:@"firstName"], [[userLogic currentUser]stringForKey:@"lastName"]];

    userInfoItem = [TableViewItem tableViewItemWithUncheckableName:userName
                                          withLeftsideImageFromUrl:[[userLogic currentUser] stringForKey:@"photo" ]];
    [userInfoItem setActionWhenSelected:^(void){
    }];
    section = [TableViewSection tableViewSectionWitName:nil
                                          selectionRule:SelectionRuleNone
                                               andItems:userInfoItem, nil];

    return section;
}

我在setNeedsLayout

中为tableViewSectionWitName:selectionRule:andItems:生成的每件商品

0 个答案:

没有答案