UITableView didSelectRowAtIndexPath , different value from what is displayed in section rows!
- (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;
}
}
is this the correct way to select certain row of value from certain section? because when i didSelectRowAtIndexpath for e.g section "C" , it is suppose to display the value that starts from array (4) . but instead at section "C" , it displays the value from array(0) ag开发者_如何学运维ain. i'm stuck for so long on this , anyone with any suggestion or help?
else if(indexPath.section == 2) // Third Section
{
if(indexPath.row >4)
{
Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row +[listOfItems count] +3];
_XMLDetailsView.aDirectory = aDirectory;
}
}
Try this, I think it helps you.
Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row];
statement at the start of the method chooses the directory using indexPath.row
which will not be from the correct section. Try indexPath.section
for this.
Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.section];
精彩评论