2011-11-10 8 views
0

twitter iPhoneアプリでは、My Profileビューに2行のセクションがあり、フォロー、フォロワー、つぶやき、お気に入りの統計情報が表示されますUIButtonの効果。今私はそれがどのように作成されたのだろうか - 各ボタンの画像を使用しているのだろうか?もっと明確にするには、次のようなものです。UITableViewCellの2つのボタンが並んでいます

|-----------------------| 
| 23  | 11 | 
| Following | tweets | <-- tableview cell 1 
|   |   | 
|-----------------------| 
| 3  | 11 | 
| Followers |favorites | <--- tableview cell 2 
|   |   | 
|-----------------------| 

答えて

0

あなたのTwitterアプリについてはわかりませんが、カスタムセルを作成して2つのボタンを追加することができます。次に、セルがインスタンス化されたら、必要に応じてセレクタとカスタム背景画像を指定できます。

@interface CustomCell : UITableViewCell { 
UIButton* leftButton; 
UIButton* rightButton; 
} 
@property(nonatomic, retain) IBOutlet UIButton* leftButton; 
@property(nonatomic, retain) IBOutlet UIButton* rightButton; 
@end 

@implementation CustomCell 

@synthesize leftButton, rightButton; 

-(id) initWithFrame:(CGRect)frame reuseIdentifier:(NSString*)reuseIdentifier { 
    if(self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) { 
     // init 
    } 
    return self; 
} 

-(void) setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:selected animated:animated]; 

    // configure for selected 
} 

- (void)dealloc { 
    [rightButton release]; 
    [leftButton release]; 
    [super dealloc]; 
} 

@end 

// in root view controller: 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"CustomCellIdentifier"; 

    // Dequeue or create a cell of the appropriate type. 
    CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 
     for(id oneObject in nib) { 
      if([oneObject isKindOfClass:[CustomCell class]]) cell = (CustomCell*)oneObject; 
     } 
    } 

    NSInteger row = indexPath.row; 

    UIButton* tempButton = cell.leftButton; 
    tempButton.tag = row * 2; 
    [tempButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    [tempButton setBackgroundImage:[thumbnails objectAtIndex:(row * 2)] forState:UIControlStateNormal]; 

    tempButton = cell.rightButton; 
    tempButton.tag = (row * 2) + 1; 
    [tempButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    [tempButton setBackgroundImage:[thumbnails objectAtIndex:((row * 2) + 1)] forState:UIControlStateNormal]; 

    return cell; 
} 

このコードは少し古いですが、その点を示しています。

+0

ありがとうございます!だから私はカスタムボタンを作成する必要があります。 – tom

関連する問題