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;

}

}

这是从某个部分选择某行值的正确方法吗?因为当我为例如“C”部分做选择行时索引路径时,假设显示从数组 (4) 开始的值。但在 "C" 部分,它再次显示来自 array(0) 的值。我被困了这么久,有人有任何建议或帮助吗?

4

2 回答 2

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

该方法开头的语句选择使用的目录,该目录indexPath.row不会来自正确的部分。试试indexPath.section这个。

 Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.section];
于 2011-05-09T07:04:49.863 回答
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;
    }
}

试试这个,我想它对你有帮助。

于 2011-05-09T07:20:41.493 回答