UITableView didSelectRowAtIndexPath ,与部分行中显示的值不同!

发布于 2024-11-06 01:27:30 字数 1101 浏览 0 评论 0原文

- (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”部分执行SelectRowAtIndexpath时,它应该显示从数组 (4) 开始的值。但在“C”部分,它再次显示 array(0) 中的值。我在这件事上坚持了很长时间,有人有任何建议或帮助吗?

- (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) again. i'm stuck for so long on this , anyone with any suggestion or help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜扑 2024-11-13 01:27:30
else if(indexPath.section == 2) // Third Section
{

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

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

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.

揽清风入怀 2024-11-13 01:27:30
Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.row];

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

 Directory *aDirectory = [appDelegate.directories objectAtIndex:indexPath.section];
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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文