2012-12-13 75 views
0
選擇單元格

喜的朋友這是一個奇怪的問題,我面對的,我用的多UItableCustomCells在一個分組TableView中與科的。能不能從的tableView

我可以只選擇第一部分中的行,然後當我點擊其他部分的排它的選擇方法不工作,我不明白的地方是錯誤的,我cellForRowAtIndexPath代碼如下: -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 


    NSString *CellIdentifier =[NSString stringWithFormat:@"%d",indexPath.row]; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    //if (cell == nil) { 




    if(indexPath.section==0) 
    { 
     if(indexPath.row==0) 
     { 
      [[NSBundle mainBundle]loadNibNamed:@"CustomCell1" owner:self options:nil]; 
      cell = self.Cell1; 
      self.Cell1 = nil; 

      txtincidentName = (UITextField*)[cell.contentView viewWithTag:1]; 





     } 
     else if(indexPath.row==1) 
     { 
      [[NSBundle mainBundle]loadNibNamed:@"CustomCell2" owner:self options:nil]; 
      cell = self.Cell2; 
      self.Cell2 = nil; 
      lblDatefirst = (UILabel*)[cell.contentView viewWithTag:2]; 
      btnCalfirst = (UIButton*)[cell.contentView viewWithTag:3]; 
      lblTimeFirst = (UILabel*)[cell.contentView viewWithTag:4]; 

     } 
     else if(indexPath.row==2) 
     { 
      [[NSBundle mainBundle]loadNibNamed:@"CustomCell2" owner:self options:nil]; 
      cell = self.Cell2; 
      self.Cell2 = nil; 

      lblDatefirst = (UILabel*)[cell.contentView viewWithTag:2]; 
      btnCalfirst = (UIButton*)[cell.contentView viewWithTag:3]; 
      lblTimeFirst = (UILabel*)[cell.contentView viewWithTag:4]; 
      lblInciTime =(UILabel*)[cell.contentView viewWithTag:9]; 
      [email protected]"Date/Time"; 

     } 

    } 
    else if(indexPath.section==1) 
    { 
     if(indexPath.row==0) 
     { 
      [[NSBundle mainBundle]loadNibNamed:@"CustomCell3" owner:self options:nil]; 
      cell = self.Cell3; 
      self.Cell3 = nil; 

      btndropDown1 = (UIButton*)[cell.contentView viewWithTag:5]; 
      btndropDown2 = (UIButton*)[cell.contentView viewWithTag:6]; 
      btndropDown3 = (UIButton*)[cell.contentView viewWithTag:7]; 

     } 
     else if(indexPath.row==1) 
     { 
      [[NSBundle mainBundle]loadNibNamed:@"CustomCell4" owner:self options:nil]; 
      cell = self.Cell4; 
      self.Cell4 = nil; 
      txtViewofdetails = (UITextView*)[cell.contentView viewWithTag:7]; 
     } 


    } 


     return cell; 


} 

模擬圖像

enter image description here

請幫助和指導謝謝。

+1

的流量,你可以從後'DidselectRowAtindexPath'一些代碼? –

+0

使斷點didSelectRow..are你能夠訪問此/ ..? – Rajneesh071

+0

不藍線出現在選擇 –

回答

0

不要這樣從筆尖加載細胞。代替寄存器將細胞與在NIB重用標識符。這將導致出隊挑基於標識的正確細胞protoype。

最有可能您目前的做法打亂了表視圖的觸摸操作。

0

哎嘗試這種類型的概念和代碼

NSString *CellIdentifier =[NSString stringWithFormat:@"%d%d",indexPath.section,indexPath.row]; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell1" owner:self options:nil]; 

     for (id currentObject in topLevelObjects){ 
      if ([currentObject isKindOfClass:[UITableViewCell class]]){ 
       cell = (CustomCell1 *) currentObject; 
       break; 
      } 
     } 
    } 
+0

,但我有4個不同的自定義單元格.... :(可以請您如上編輯我的代碼..? –

+0

哎@NitinGohel只是使用的概念和設置條件的,如果條件,如果它零然後創建它,也只是張貼didselect方法花花公子的代碼.. –

+0

是BHAI沒有選擇馬凱代碼nathi responsĴnathi麥芽選擇行沒有BHAI –