2013-07-18 31 views
2

我有一個故事板UITableViewController。在這個控制器中,我有靜態單元格,其中一個是UITableViewCell的子類。在IB中,我向該靜態單元添加了一個UIButton,並將其連接到UITableViewCell子類中的IBAction。但是,IBAction從未被調用過。爲什麼這不起作用?如何通過IB觸發單元內的按鈕來達到所需的行爲?如何在故事板靜態單元格中從UIButton觸發IBAction?

.H

#import <UIKit/UIKit.h> 

@interface BSWorkoutsCell : UITableViewCell 

@property (nonatomic, weak) IBOutlet UIButton *button; 
@property (nonatomic, strong) IBOutletCollection(UIButton) NSArray *buttons; 

- (IBAction)tapButton:(id)sender; 
@end 

.M

- (IBAction)tapButton:(id)sender{ 
    if (!_buttonsHidden){ 
     [self animateHideButtons:(UIButton *)sender]; 
     _buttonsHidden = YES; 
    } 
} 

圖片

enter image description here

enter image description here

+0

發佈代碼將代碼連接到代碼的位置以及IBAction應該被調用的地方 – CaptJak

+0

@CaptJak我通過IB進行連接。 TouchUpInside事件已連接到我的 - (IBAction)tapButton:(id)發件人方法。 – circuitlego

+0

那太好了。請編輯您的問題並複製粘貼這些方法。你是什​​麼意思「我通過IB來做我的聯繫」。你有在相應的.h文件中聲明的屬性嗎?請發佈聲明屬性的.h文件的內容以及觸發IBActions的.m文件的內容。 – CaptJak

回答

2

我意識到,在U ITableViewCell在IB中未選中User Interaction Enabled。這使得它內部的任何子視圖都不是交互式的,因此按鈕沒有被實際按下,並且IBAction未被調用。

一旦我檢查框,一切工作正常。

相關問題