我正在处理表格视图并为tableFooterView
进行自定义。我正在做的是:
ClassA.m
- (void)viewDidLoad
{
FooterViewController *footerView = [[FooterViewController alloc] initWithNibName:@"FooterViewController" bundle:nil];
// Add selector of Class A to checkOutButton
[footerView.checkOutButton addTarget:self action:@selector(goToCheckOut) forControlEvents:UIControlStateNormal];
self.shoppingListTable.tableFooterView.backgroundColor = [UIColor clearColor];
self.shoppingListTable.tableFooterView = footerView.view;
}
- (void)goToCheckOut {
NSLog(@"this is a response from a button");
}
FootViewController.h
@interface FooterViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *amount;
@property (strong, nonatomic) IBOutlet UIButton *checkOutButton;
@end
插座也连接到xib文件
然而,当我点击按钮时,它根本没有响应,日志显示什么......
我在这里做错了什么。如果您对此有任何想法,请帮忙。感谢
答案 0 :(得分:1)
试试这个:
[footerView.checkOutButton addTarget:self action:@selector(goToCheckOut) forControlEvents:UIControlEventTouchUpInside];
答案 1 :(得分:1)
您的代码无效,因为您设置了错误的forControlEvents
参数。要通过按下按钮来调用方法,您需要使用UIControlEventTouchUpInside
。
因此请更改此行[footerView.checkOutButton addTarget:self action:@selector(goToCheckOut) forControlEvents:UIControlStateNormal];
到
[footerView.checkOutButton addTarget:self action:@selector(goToCheckOut) forControlEvents:UIControlEventTouchUpInside];