2013-10-30 29 views
2

本主题已遍布整个计算器,但我找不到合适的解决方案。UITableCell中的按钮 - 将数据传递给选择器

我在每个UITableViewCell上都有按钮。

以下是我如何创建单元格。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ExaminationCell"]; 
    UIButton *clipButton = (UIButton *)[cell viewWithTag:3]; 

    MedicalExamination *examination = [objects objectAtIndex:indexPath.row]; 

    [clipButton addTarget:self action:@selector(examinatonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

    return cell; 
} 

这里是方法thah应处理按钮点击:

-(void)examinatonClicked:(MedicalExamination*)examination 
{ 

} 

我如何通过检查对象examinatonCommentsClicked方法?显然,目标是对每个小区不同...

回答

-1

我认为你必须通过xib(custum cell)uitableviewCell添加按钮,然后通过iboutlet连接。

+0

好,Dheerendra是有点权,是可以实现这样......不过我不认为厦门国际银行是必要的,只是定制UITableVIewClass –

+0

是否有可能通过NSsstring这是全地球对象通过考试吗? –

+0

或使用称为检查的新属性创建自定义的uitableviewcell。那是所有,而不是xibs。 – AndrewShmig

3

我会做的一件有点冒失鬼的事是,我将使用UIButton的标记属性传递行号,以便可以从支持我的表的数组中抽取对象。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ExaminationCell"]; 
    UIButton *clipButton = (UIButton *)[cell viewWithTag:3]; 
    clipButton.tag = indexPath.row //Set the UIButton's tag to the row. 

    MedicalExamination *examination = [objects objectAtIndex:indexPath.row]; 

    [clipButton addTarget:self action:@selector(examinatonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

    return cell; 
} 

-(void)examinatonClicked: (id)sender 
{ 
    int row = ((UIButton *)sender).tag; 
    MedicalExamination *examination = [objects objectAtIndex: row]; 
    //Profit! 
}