J'ajoute dynamiquement un bouton dans la cellule de vue de table. Bouton affiché sur la table mais je ne suis pas en mesure de cliquer dessus. Voici mon code,Comment ajouter un bouton cliquable sur une cellule de table?
Ce tableviewcell mon code de classe:
MessageTableViewCell.h
#import <UIKit/UIKit.h>
@interface MessageTableViewCell : UITableViewCell {
{IBOutlet UIButton *chat_pic_btn;}}
@property (nonatomic, retain) UIButton *chat_pic_btn;
@end;
MessageTableViewCell.m
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {chat_pic_btn=[[UIButton alloc]init];
[self.contentView addSubview:chat_pic_btn];}}
MessageTable.m
-(void)customActionPressed :(id)sender
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Custom Button Pressed"
message:[NSString stringWithFormat: @"You pressed the custom button on cell"]
delegate:self cancelButtonTitle:@"Great"
otherButtonTitles:nil];
[alertView show];
}
- (UITableViewCell *)tableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellIdentifier";
MessageTableViewCell *cell = (MessageTableViewCell *)[myTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// cell = [[MessageTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
cell = [[MessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.chat_pic_btn.frame = CGRectMake(180, 24, 70,35);
[cell.chat_pic_btn setImage:[UIImage imageNamed:@"done.png"]forState:UIControlStateNormal];
[cell.chat_pic_btn addTarget:self action:@selector(customActionPressed:) forControlEvents:UIControlEventTouchDown];
return cell;
}
Plea Aidez-moi. Merci.
Est-ce bouton sur tous les plans? Est-il rendu correctement? – ThomasW
Ya il y a une condition si la condition est vraie alors le bouton apparaîtra sur la vue. Le bouton est affiché correctement mais je ne suis pas en mesure d'appeler une méthode au clic. – Saurabh
Vous devez probablement également afficher le code que vous utilisez pour créer les cellules du tableau. Aussi, que se passe-t-il lorsque vous cliquez sur la cellule bouton? Y a-t-il un accident? Ou pas d'effet du tout? – ThomasW