あなたの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;
}
このコードは少し古いですが、その点を示しています。
ありがとうございます!だから私はカスタムボタンを作成する必要があります。 – tom