2013-10-30 32 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! 
}