如何在NSMutableArray

时间:2016-07-13 06:50:39

标签: ios uicollectionview nsmutablearray nsindexpath

我正在尝试将indexPath存储在NSMutableArray

    [checkBoxIndexArray addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:?]];


   - (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths
    {

           cell.checkBox.image = [UIImage imageNamed:@"check"];

           [self.collectionView insertItemsAtIndexPaths:checkBoxIndexArray];

    }

但我不知道我应该为inSection赋予什么价值。我尝试输入0,1但仍然无法正常工作。我收到了以下错误

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (2) must be equal to the number of items contained in that section before the update (2), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).

我收到以下代码的错误

[self.collectionView insertItemsAtIndexPaths:checkBoxIndexArray];

请告诉我,我应该为inSection提供什么价值。

3 个答案:

答案 0 :(得分:2)

你应该使用 [checkBoxIndexArray addObject: indexPath];

答案 1 :(得分:0)

NSIndexPath *indexPath=[Your_Table_Name indexPathForSelectedRow];
[checkBoxIndexArray addObject: indexPath];

答案 2 :(得分:0)

[checkBoxIndexArray addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:?]]

与此相同

[checkBoxIndexArray addObject:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]

或者这样做

[checkBoxIndexArray addObject:indexPath]

直接添加indexPath,稍后可以根据需要访问行或节值。