2012-06-20 84 views
0

我的表视图的工作和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文件以及

然而,当我点击按钮,它根本没有回应,日志中什么也没有显示出来......

我在做什么错在这里。如果您对此有任何想法,请提供帮助。因为设置了错误的forControlEvents参数

[footerView.checkOutButton addTarget:self action:@selector(goToCheckOut) forControlEvents:UIControlEventTouchUpInside]; 

回答

1

试试这个。要通过按下按钮来调用方法,您需要使用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

+0

我知道我在做什么错在这里。首先,我做了一个像你说的改变,然后在将'footerView.view'分配给'self.shoppingListTable.tableFooterView'后,我必须交换'addTarget'行。 – tranvutuan

1

您的代码不工作:谢谢

+0

请看我上面的评论。谢谢 – tranvutuan