2013-07-30 33 views
1

我在xib中创建了一个自定义单元格(在iOS6中使用Storyboards,但是为单元格创建了单独的xib),现在我试图将我的扬声器按钮连接到我的UITableViewController sublcass中的IBAction。在xib上的自定义单元格上设置IBAction?

enter image description here

我注册了我的手机在我viewDidLoad中:

[self.tableView registerNib:[UINib nibWithNibName:@"MissedWordTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MissedWordCell"]; 

我已经尝试了几种不同的方法来添加目标。例如,在我的tableView:cellForRowAtIndexPath中,我试图直接添加目标。

static NSString *CellIdentifier = @"MissedWordCell"; 
MissedQuestionEntity *missedQuestion; 

// forIndexPath: is iOS6 
MissedWordTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
// Add target here? Didn't work. @selector(playWordAction) or @selector(playWordAction:) 
// [cell.playAudioBtn addTarget:self action:@selector(playWordAction) forControlEvents:UIControlEventTouchUpInside]; 

我也试图设置文件所有者,以我的表视图控制器在我的自定义单元格厦门国际银行,但仍然没有工作。

这里是我的错误信息:

2013-07-30 07:47:15.833 Spanish[69420:c07] *** Terminating app due to uncaught exception  
'NSInvalidArgumentException', reason: '-[__NSArrayI doIt]: unrecognized selector sent to instance  
0xec34430' 
*** First throw call stack: 
(0x231e012 0x172de7e 0x23a94bd 0x230dbbc 0x230d94e 0x1741705 0x6752c0 0x675258 0x736021 0x73657f 0x7356e8  
0x6a4cef 0x6a4f02 0x682d4a 0x674698 0x1c0bdf9 0x1c0bad0 0x2293bf5 0x2293962 0x22c4bb6 0x22c3f44 0x22c3e1b  
0x1c0a7e3 0x1c0a6 
+1

要调用'doIt'方法在某个地方在你的代码中,请检查 –

+0

是的,那是我在自定义单元格xib中向文件所有者(我的UITableViewController的子类)所做的IBAction连接。 – h4labs

+0

doIt IBAction playAudioBtn按钮?或者是其他东西? – DharaParekh

回答

5

的UITableViewCell刚刚注册的属性:

@property (strong, nonatomic) IBOutlet UIButton *playSoundButton; 

在你的UITableViewController

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self.tableView registerNib:[UINib nibWithNibName:@"YourCustomCell" bundle:nil] forCellReuseIdentifier:@"YourCustomCell"]; 
    // ... 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    YourCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YourCustomCell"]; 

    [[cell playSoundButton] addTarget:self action:@selector(playWordAction:) forControlEvents:UIControlEventTouchUpInside]; 

    //... 
} 

-(IBAction) playWordAction:(id) sender 
{ 
    // do what you want to 
} 
+0

这看起来像我所描述的,我试过的东西?这有什么不同?我的选择器没有找到。我必须错过别的东西? – h4labs

+0

我想你是在UITableViewCell上添加一个IBAction,但是你不需要!只需注册财产,或...看看“ - (IBAction)playWordAction:(id)发件人” –

+0

没关系。这确实有用。在尝试第二种方法之前,我一定有其他错误。 – h4labs

相关问题