2012-03-29 13 views
1

私はおそらく非常に基本的な質問があります。 Xibファイルを使わずにカスタムセルをプログラムで作成しています。私のCustomHell.mファイルには、基本的にinitWithStyleとlayoutSubviewsという2つのメソッドしかありません。 私はいくつかのラベルとボタンをプログラムで追加することができました。今、私は特定のカスタムビュー、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 

答えて

0

[self addSubview: storeName]を試してみてください代わりに、 [self.contentView addSubview:storeName]

+0

これは表示されませんでしたork。しかし、私はこの問題を回避するために、XIBファイルを使用し、FacebookLikeViewをIB経由で接続しました。 – Giovanni

関連する問題