2012-06-20 99 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