2013-01-16 126 views
0

我使用的按鈕組具有不同的圖像和tableview與我的project.every單元格中的自定義單元格按組每個按鈕時單元格將會有一組組件(如imageview,按鈕,標籤,滑塊)被添加。 我的按鈕圖像,也添加到單元格的imageview。獲取表格的索引路徑

當我再次按下按鈕時,如何獲得每個單元格的索引。

當我第一次按下按鈕時,將會添加單元格。 當第二次按下,我想增加單元格內的標籤值。所以我需要indexpath從單元格中的單元格從tableview。

+0

cell.index?這是你在找什麼? – lakesh

+0

單元格將在第一次按下按鈕時添加。 – Krishnan8190

+0

當第二次按第二次我想增加單元格內的標籤值。因此,我需要indexpath從單元格的表格單元格 – Krishnan8190

回答

0

我不確定你在找什麼,也許你可以澄清你想要做什麼。

方法indexPathForCell:是一個UITableView方法,它爲您提供某個單元格的索引。

澄清你的問題,也許我們可以幫助更多。

1

可以調用按鈕觸摸事件獲得的UITableView的細胞 -

UIView *cellView = (UIVIew *)[button superview]; 
UITableViewCell *cell = (UITableViewCell *)[cellView superview]; 
NSIndexPath *indexPath = [self.tableview indexPathForCell:cell]; 
+0

你假設按鈕是單元格的直接子視圖。然而這個方法和我一樣。無論哪種方式,使用superview做這種東西不是很好。我建議OP讓他們思考一下他們​​的架構,並考慮重新設計。 – Bergasms

+0

@Bergasms是的,你是對的,需要了解他們的架構。我會制定出另一個選項並儘快編輯答案。 –

+0

幫我解決這個問題。 – Krishnan8190

0

不知道你的細胞,表或類似的東西的結構。此代碼將起作用。

-(NSIndexPath *) pathForButton:(UIbutton *) b { 
     UITableView *tv = nil; 
     UIView *superView = [b superview]; 
     UIView *cell; 
     while(superview != nil && ![superview isKindOfClass:[UITableView class]]){ 
      cell = superview; 
      superview = [superview superview]; 
     } 

     if(superview != nil && cell != nil){ 
      tv = (UITableView*)superview; 

      return [tv indexPathForCell:cell]; 
     } 
     return nil; 
} 
+0

按鈕不在單元格內 – Krishnan8190

+0

我有7個按鈕 – Krishnan8190

+0

當按下每個按鈕時,單元格將與按鈕圖像一起添加。 – Krishnan8190