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
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.
If you wanted to keep your loop running forwards, you could either:
decrement i
when your condition is met and you removeObjectAtIndex
if (cell.imageView.image == isCkDone) {
...
--i ;
...
}
or increment i
only when your condition is not met:
for ( int i=0 ; i<c ; ) {
...
if (cell.imageView.image == isCkDone) {
...
} else {
++i ;
}