Le button dans le pied de table n'est pas appelé

J'ai déclaré UIView et UIButton dans l' UIView

 -(void)viewWillAppear:(BOOL)animated { footerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,300)]; UILabel *totallabel = [[UILabel alloc]initWithFrame:CGRectMake(50,5,320,40)]; totallabel.text = @"Grand Total ="; totallabel.font = [UIFont fontWithName:@"Lato-Regular" size:10]; totallabel.font = [UIFont systemFontOfSize:14]; [footerView addSubview:totallabel]; UILabel *lblRs = [[UILabel alloc]initWithFrame:CGRectMake(160,5,320,40)]; lblRs.text = @"Rs."; lblRs.font = [UIFont fontWithName:@"Lato-Regular" size:10]; lblRs.font = [UIFont systemFontOfSize:14]; [footerView addSubview:lblRs]; totalcostlabel = [[UILabel alloc]initWithFrame:CGRectMake(190,5,320,40)]; totalcostlabel.font = [UIFont fontWithName:@"Lato-Regular" size:10]; totalcostlabel.font = [UIFont systemFontOfSize:14]; [footerView addSubview:totalcostlabel]; UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; aButton.frame = CGRectMake(70,50,150,40); aButton.backgroundColor = [UIColor colorWithRed:119.0/225.0 green:49.0/255.0 blue:88.0/255.0 alpha:1.0]; [aButton setTitle:@"Checkout" forState:UIControlStateNormal]; [aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; aButton.titleLabel.font = [UIFont fontWithName:@"Lato-Regular" size:10]; [aButton addTarget:self action:@selector(btnChackOut:) forControlEvents:UIControlEventTouchUpInside]; [footerView addSubview:aButton ]; [self.tblView setTableFooterView:footerView]; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return footerView; } - (void)btnChackOut:(UIButton *)sender { NSLog(@"btn clicked"); } 

Lorsque je clique sur le button Checkout qui est déclaré dans mon pied de page, l'événement click n'est pas effectué et la méthode d'action n'est pas appelée

J'ai eu la solution et maintenant cela a fonctionné. Appliquez le code ci-dessous.

en .h

  #import "CustomCell.h" -(IBAction)actionContinue:(id)sender; @property (strong, nonatomic) IBOutlet UITableView *tblViewCart; 

dans M

 @synthesize tblViewCart; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. arrayImageCart = [[NSMutableArray alloc]initWithObjects:@"ios7.jpg",@"iphone_6.jpg",nil]; arrayPrice = [[NSMutableArray alloc]initWithObjects:@"Rs 60,000",@"Rs 55,000",nil]; arrayDescription = [[NSMutableArray alloc]initWithObjects:@"Made In China",@"Headquarter is in US",nil]; arrayOtherDetail = [[NSMutableArray alloc]initWithObjects:@"Black Color",@"White Color",nil]; arraySubTotal = [[NSMutableArray alloc]initWithObjects:@"Rs 60,000",@"Rs 55,000",nil]; arrayTotal = [[NSMutableArray alloc]initWithObjects:@"110000",nil]; arrayTotalCharges = [[NSMutableArray alloc]initWithObjects:@"2000",nil]; arrayYouPay = [[NSMutableArray alloc]initWithObjects:@"112000", nil]; self.tblViewCart.separatorColor = [UIColor clearColor]; } // Button Action -(IBAction)actionContinue:(id)sender { } #pragma mark - UITableView Delegate Methods -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 203; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(section==0) return arrayPrice.count; else return arrayYouPay.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"Reuse"]; NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil]; if(indexPath.section==0) { cell = [nib objectAtIndex:0]; cell.imageViewCart.image = [UIImage imageNamed:[NSSsortingng ssortingngWithFormat:@"%@",[arrayImageCart objectAtIndex:indexPath.row]]]; cell.lblPriceDetails.text = [NSSsortingng ssortingngWithFormat:@"%@",[arrayPrice objectAtIndex:indexPath.row]]; cell.lblDescriptionAbtProduct.text = [NSSsortingng ssortingngWithFormat:@"%@",[arrayDescription objectAtIndex:indexPath.row]]; cell.labelOtherDetails.text = [NSSsortingng ssortingngWithFormat:@"%@",[arrayOtherDetail objectAtIndex:indexPath.row]]; cell.lblSubTotal.text = [NSSsortingng ssortingngWithFormat:@"%@",[arraySubTotal objectAtIndex:indexPath.row]]; } else { cell = [nib objectAtIndex:1]; cell.lblTotal.text = [NSSsortingng ssortingngWithFormat:@"%@",[arrayTotal objectAtIndex:indexPath.row]]; cell.lblTotalCharges.text = [NSSsortingng ssortingngWithFormat:@"%@",[arrayTotalCharges objectAtIndex:indexPath.row]]; cell.lblYouPay.text = [NSSsortingng ssortingngWithFormat:@"%@",[arrayYouPay objectAtIndex:indexPath.row]]; } return cell; } 

Créer une cellule personnalisée via NewFile-> Source-> CocoaTouchClass-> Suivant> SubClassof: UITableViewCell, Class-> CustomClass avec CheckBox Créer aussi un file XIB (Ceci est pour les détails de prix). Ensuite, le file Inside CustomCell.xib crée un autre UITableViewCell et donne le nom CustomCell pour Total Amount and Pay.

Impossible d'appeler parce que vous ne définissez pas une hauteur pour le pied de page, il vous suffit de définir la hauteur du pied de page comme suit:

 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 300; } 
 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 40; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *footerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 304, 40)]; footerView.backgroundColor = [UIColor whiteColor]; UIButton *add_member=[UIButton buttonWithType:UIButtonTypeCustom]; add_member.layer.borderWidth = 0.8; add_member.layer.cornerRadius = 10; add_member.layer.masksToBounds = YES; add_member.layer.borderColor =[[UIColor lightGrayColor] CGColor]; add_member.layer.shadowColor = [[UIColor whiteColor] CGColor]; add_member.layer.shadowOffset = CGSizeMake(0.0, 0.0); add_member.layer.shadowOpacity = 0.0; [add_member setTitle:@"Add Member" forState:UIControlStateNormal]; add_member.titleLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:16]; [add_member addTarget:self action:@selector(AddNewMember:) forControlEvents:UIControlEventTouchUpInside]; [add_member setTitleColor:[UIColor colorWithRed:140.0/255.0 green:198.0/255.0 blue:63.0/255.0 alpha:1.0] forState:UIControlStateNormal];//set the color this is may be different for iOS 7 add_member.frame=CGRectMake(10, 5, 284, 30); //set some large width to ur title [footerView addSubview:add_member]; return footerView; } #pragma mark - Add member -(IBAction)AddNewMember:(id)sender { //Some code } 

Faites la propriété pour le button et mentionnez le nom de la propriété dans le bloc d'action comme ceci.

 -(IBAction)btn_check:(id)sender { BOOL buttonstate;//default state is false. if(!buttonstate) { //Declare your action code here. //Use the button property name here for your action. } else { //Declare the button release code here ,its not mandatory. }