Как программно добавить пользовательский вид в пользовательскую ячейку? - PullRequest
1 голос
/ 29 марта 2012

У меня есть вопрос, который, возможно, очень простой.Я создаю пользовательскую ячейку без Xib-файла, все программно.В моем файле CustomHell.m у меня есть только два метода: initWithStyle и layoutSubviews.Мне удалось программно добавить несколько ярлыков и кнопку.Теперь я хочу добавить определенный пользовательский вид - FacebookLikeView (https://github.com/brow/FacebookLikeView)) - но я не знаю, как это сделать. Это код в моем "initWithStyle: reuseIdentifier:

    //StoreName Label
    storeName = [[UILabel alloc] init];
    storeName.textAlignment = UITextAlignmentLeft;
    storeName.font = [UIFont boldSystemFontOfSize: 16]; //12
    storeName.backgroundColor = [UIColor clearColor];
    storeName.adjustsFontSizeToFitWidth = YES;

    //checkIn Button
    checkInButton = [UIButton buttonWithType:UIButtonTypeCustom];
    checkInButton.frame = CGRectMake(203,10,86,25);
    [checkInButton setImage:[UIImage imageNamed:@"Check-In.png"] forState:UIControlStateNormal];
    [checkInButton addTarget:self.nextResponder action:@selector(addCheckin:) forControlEvents:UIControlEventTouchUpInside];
    checkInButton.backgroundColor = [UIColor redColor];

    //FACEBOOK
    facebookLikeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    facebookLikeButton.frame = CGRectMake(169,40,119,25);

    [self.contentView addSubview:storeName];
    [self.contentView addSubview:storeAddress];
    [self.contentView addSubview:subtitle];
    [self.contentView addSubview:checkInButton];
    [self.contentView addSubview:facebookLikeButton];
    //[self.contentView addSubview:likeButton];
return self;

И это мойlayoutSubviews:

[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;

storeName.frame = CGRectMake(boundsX+10, 15, 190, 20);
storeAddress.frame = CGRectMake(boundsX+10, 42, 200, 40); 
subtitle.frame = CGRectMake(boundsX+10, 77, 280, 30);
likeButton.frame = CGRectMake(boundsX+199, 42, 50, 20);

Заголовочный файл выглядит так:

#import "FacebookLikeView.h"
@interface CustomCellHead : UITableViewCell
{
FacebookLikeView *likeButton;

UIButton *facebookLikeButton;
UIButton *checkInButton;
UILabel *storeName;
UILabel *storeAddress;
UILabel *subtitle;
}

@property(nonatomic,retain) FacebookLikeView *likeButton;
@property(nonatomic,retain) UIButton *checkInButton;
@property(nonatomic,retain) UILabel *storeName;
@property(nonatomic,retain) UILabel *storeAddress;
@property(nonatomic,retain) UILabel *subtitle;

@end

1 Ответ

0 голосов
/ 29 марта 2012

Попробуйте [self addSubview: storeName] вместо [self.contentView addSubview: storeName]

...