Iphone UITableView didSelectRowAtIndexPath,与节行中显示的值不同!
} 这是从特定节中选择特定值行的正确方法吗?因为当我为例如“C”部分选择Rowatindexpath时,假设它显示从数组(4)开始的值。但在“C”部分,它会再次显示数组(0)中的值。我在这件事上耽搁了这么久,有人能给我建议或帮助吗Iphone UITableView didSelectRowAtIndexPath,与节行中显示的值不同!,iphone,xcode,didselectrowatindexpath,Iphone,Xcode,Didselectrowatindexpath,} 这是从特定节中选择特定值行的正确方法吗?因为当我为例如“C”部分选择Rowatindexpath时,假设它显示从数组(4)开始的值。但在“C”部分,它会再次显示数组(0)中的值。我在这件事上耽搁了这么久,有人能给我建议或帮助吗 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Directory *aDirectory = [appDelegate.di
- (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;
}
方法开头的语句使用indexPath.row
选择目录,该目录将不会来自正确的部分。为此,请尝试indexPath.section
Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row];
试试这个,我认为它对您有帮助。当我使用indexPath.section时,它没有帮助。section A将有itemA section B将有itemB,itemB(假设该节中有2个项目),然后section C将有itemC,itemC。为什么会这样?当我使用indexPath.row section A将有itemA,itemB,itemC section B将有itemA,itemB,section C将有itemA,itemB,itemC我想要的是section A将有itemA,itemB section B将有itemC,itemD,itemE等等..试试这个目录*aDirectory=[appDelegate.directories objectAtIndex:indexPath.section];
Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.section];
else if(indexPath.section == 2) // Third Section
{
if(indexPath.row >4)
{
Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row +[listOfItems count] +3];
_XMLDetailsView.aDirectory = aDirectory;
}
}