0

Currently I have a while statement that loops through all cells below that are of a lower padding level and is supposed to remove said cells. Currently the below statement goes through about 3 of them then stops even though further cells meet the conditions.

if isExpanded[indexPath.item] //if already expanded remove
{
    var t = 1

    while (comment.paddingLevel != commentsData[indexPath.row + t].paddingLevel)
    {
        isExpanded.removeAtIndex(indexPath.row + t)

        preRenderedText.removeAtIndex(indexPath.row + t)
        commentsData.removeAtIndex(indexPath.row + t)

        var path = NSIndexPath(forItem: indexPath.row + t, inSection: 0)
        t++
        delpaths.append(path)        
    }
}
2
  • 1
    You are mutating the isExpanded array by deleting items from it - this means that the index for the next item is going to reduce by one, but you increment t regardless. An NSMutableIndexSet is probably a better data structure to use for isExpanded rather than an array. Commented Jan 3, 2016 at 22:32
  • @Paulw11 Your comment should be an answer. Commented Jan 4, 2016 at 1:07

1 Answer 1

2

You are mutating the isExpanded array by deleting items from it - this means that the index for the next item is going to reduce by one, but you increment t regardless. An NSMutableIndexSet is probably a better data structure to use for isExpanded rather than an array.

An NSMutableIndexSet stores a set of integer indices - In this case it would be your item values. Then you can use the set's contains(item) method to quickly get an answer as to whether a particular index is in the set or not.

Sign up to request clarification or add additional context in comments.

1 Comment

Currently my array is a bool array how can I adapt NSMutableIndexSet to fit the same purpose?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.