0

我正在处理表格视图并进行自定义。tableFooterView我正在做的是:

类A.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 文件

但是,当我单击按钮时,它根本没有响应,并且日志什么也没有显示......

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

4

2 回答 2

1

试试这个:

[footerView.checkOutButton addTarget:self action:@selector(goToCheckOut) forControlEvents:UIControlEventTouchUpInside];
于 2012-06-20T17:34:09.150 回答
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

于 2012-06-20T17:44:00.243 回答