按钮没有响应点击事件,

时间:2012-06-20 17:11:21

标签: iphone

我正在处理表格视图并为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文件

然而,当我点击按钮时,它根本没有响应,日志显示什么......

我在这里做错了什么。如果您对此有任何想法,请帮忙。感谢

2 个答案:

答案 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];

请检查控制事件参考:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIControl_Class/Reference/Reference.html