【问题标题】:How to add multiple NSIndexPath into NSMutableArray如何将多个 NSIndexPath 添加到 NSMutableArray
【发布时间】:2013-04-30 08:47:02
【问题描述】:

我正在尝试将 nsindexpath 添加到数组中 .. 我只能添加一个 indexpath 。如果我尝试将另一个 indexpath 添加到数组中 ..调试器仅显示最新的 indexpath 。

 for (int i = 0 ; i<[notificationArray count]; i++)
        {
            selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber];
            selectedSympIPArray = [[NSMutableArray alloc]init];
            [selectedSympIPArray addObject:selectedSymptIndexPath];
        }

即使我尝试将 [selectedSympIPArray addObject:selectedSymptIndexPath]; 放在 for 循环之外,它仍然只添加最新的索引路径而不是显示多个索引路径

【问题讨论】:

    标签: iphone ios objective-c nsmutablearray nsindexpath


    【解决方案1】:

    你每次都在循环中分配初始化数组,不要那样做。

    试试这个:

    selectedSympIPArray = [[NSMutableArray alloc]init];
    
    for (int i = 0 ; i<[notificationArray count]; i++)
    {
       selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber];
       [selectedSympIPArray addObject:selectedSymptIndexPath];
    }
    

    【讨论】:

    • 但是当我滚动 uitableview 一段时间后它会变慢
    【解决方案2】:

    在您的代码中,您每次都在迭代中分配。这是完全错误的。找出你的错误。

    您可以使用此代码....

    selectedSympIPArray = [NSMutableArray array];
    for (int i = 0 ; i<[notificationArray count]; i++)
            {
                selectedSymptIndexPath = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber];            
                [selectedSympIPArray addObject:selectedSymptIndexPath];
            }
    

    【讨论】:

      猜你喜欢
      • 2012-01-23
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多