2011-05-09 57 views
1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row]; 
    _XMLDetailsView.aDirectory = aDirectory; 

if (indexPath.section == 0) // First section 
{ 
    _XMLDetailsView.aDirectory = aDirectory; 
} 
else if(indexPath.section == 1) // Second Section 
{ 
    Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row +[listOfItems count]]; 
    _XMLDetailsView.aDirectory = aDirectory; 

} 
else if(indexPath.section == 2) // Third Section 
{ 
    Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row +[listOfItems count] +3]; 
    _XMLDetailsView.aDirectory = aDirectory; 

} 
else if(indexPath.section == 3) // Fourth Section 
{ 
    Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row +[listOfItems count] +9]; 
    _XMLDetailsView.aDirectory = aDirectory; 

} 

}UITableView didSelectRowAtIndexPath,與部分行中顯示的值不同!

這是正確的方法,從某些部分選擇的價值一定行?因爲當我didSelectRowAtIndexpath例如節「C」,它是假設顯示從數組(4)開始的值。而是在「C」部分,它再次顯示數組(0)中的值。我對此持續了這麼久,任何有任何建議或幫助的人?在方法的開始

回答

0
else if(indexPath.section == 2) // Third Section 
{ 

    if(indexPath.row >4) 
    { 
     Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row +[listOfItems count] +3]; 
     _XMLDetailsView.aDirectory = aDirectory; 
    } 
} 

試試這個,我認爲它可以幫助你。

0
Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row]; 

聲明選擇使用indexPath.row該不會是從正確部分的目錄。試試indexPath.section

Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.section]; 
+0

它沒有幫助,當我使用indexPath.section。 sectionA將有itemA sectionB將有itemB,itemB(假設它有2個項目在該部分), 然後部分C將有itemC,itemC。爲什麼這樣呢? – 2011-05-09 07:16:53

+0

當我使用indexPath.row 部1.將意達,itemB,itemC sectionB會有意達,itemB 和sectionC會有意達,itemB,itemC 我想是 部1.將意達,itemB sectionB會有itemC,itemD,itemE 等等.. – 2011-05-09 07:18:01

+0

試試這個目錄* aDirectory = [appDelegate.directories objectAtIndex:indexPath.section]; – visakh7 2011-05-09 07:23:31

相關問題