tableview页脚中的button没有被调用

我已经在UIView声明了UIViewUIButton

 -(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"); } 

当我单击我的页脚中声明的签出button时单击事件不执行,操作方法不会被调用

我得到了解决scheme,现在它已经work.Apply下面的代码。

在.h

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

以.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:[NSString stringWithFormat:@"%@",[arrayImageCart objectAtIndex:indexPath.row]]]; cell.lblPriceDetails.text = [NSString stringWithFormat:@"%@",[arrayPrice objectAtIndex:indexPath.row]]; cell.lblDescriptionAbtProduct.text = [NSString stringWithFormat:@"%@",[arrayDescription objectAtIndex:indexPath.row]]; cell.labelOtherDetails.text = [NSString stringWithFormat:@"%@",[arrayOtherDetail objectAtIndex:indexPath.row]]; cell.lblSubTotal.text = [NSString stringWithFormat:@"%@",[arraySubTotal objectAtIndex:indexPath.row]]; } else { cell = [nib objectAtIndex:1]; cell.lblTotal.text = [NSString stringWithFormat:@"%@",[arrayTotal objectAtIndex:indexPath.row]]; cell.lblTotalCharges.text = [NSString stringWithFormat:@"%@",[arrayTotalCharges objectAtIndex:indexPath.row]]; cell.lblYouPay.text = [NSString stringWithFormat:@"%@",[arrayYouPay objectAtIndex:indexPath.row]]; } return cell; } 

通过NewFile-> Source-> CocoaTouchClass-> Next> SubClassof:UITableViewCell,Class-> CustomClass与CheckBox创build自定义单元格同时创buildXIB文件(这是价格细节)。 然后在CustomCell.xib文件中创build另一个UITableViewCell,并为总金额和付款命名为CustomCell。

无法调用,因为您没有设置页脚的高度,只需要像这样设置页脚的高度:

 - (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 } 

使button的属性,并提到这样的行动块内的属性名称。

 -(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. }