【问题标题】:UITableView didSelectRowAtIndexPath , different value from what is displayed in section rows!UITableView didSelectRowAtIndexPath ,与部分行中显示的值不同!
【发布时间】:2011-05-09 06:51:19
【问题描述】:
- (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) 的值。我被困了这么久,有人有任何建议或帮助吗?

【问题讨论】:

    标签: iphone xcode didselectrowatindexpath


    【解决方案1】:
    else if(indexPath.section == 2) // Third Section
    {
    
        if(indexPath.row >4)
        {
            Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row +[listOfItems count] +3];
           _XMLDetailsView.aDirectory = aDirectory;
        }
    }
    

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

    【讨论】:

      【解决方案2】:
      Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row];
      

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

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

      【讨论】:

      • 当我使用 indexPath.section 时,它没有帮助。 sectionA 将有 itemA sectionB 将有 itemB,itemB (假设它在该部分中有 2 个项目),然后 C 部分将有 itemC,itemC 。为什么会这样?
      • 当我使用 indexPath.row sectionA 将有 itemA,itemB,itemC sectionB 将有 itemA,itemB 和 sectionC 将有 itemA,itemB,itemC 我想要的是 sectionA 将有 itemA,itemB sectionB 将有 itemC,itemD,itemE 等等..
      • 试试这个目录 *aDirectory = [appDelegate.directories objectAtIndex:indexPath.section];
      猜你喜欢
      • 2021-06-24
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      • 2020-05-27
      相关资源
      最近更新 更多