Deleting objects within a for loop from a NSMutableArray

前端 未结 2 1496
你的背包
你的背包 2021-01-24 10:11

I am working with a UITableView and for each of the objects in the array that is the datasource for the UITableView, I am deleting them if they meet a

2条回答
  •  失恋的感觉
    2021-01-24 10:40

    You must run your loop backwards, i.e.

    for (int i=c-1;i>=0;--i)
    

    If you are running it the other way round, removing an object at index position i moves the objects in the array that are behind i one position forward. In the end you will even run over the bounds of your array.

提交回复
热议问题