The group assignment problem occurs when values are passed in the interface. The interface transfers array assignments.
Today, it takes a lot of time to call a bug. Take notes here.
Two simple controllers in the project perform attribute value transfer
YuLanViewController * vc = [[YuLanViewController alloc] init]; vc. dataArray = self. images; vc. returnDataBlock = ^ (NSInteger indexOfData) {[self. images removeObjectAtIndex: indexOfData]; // refresh [self configImages];}; [self. navigationController pushViewController: vc animated: YES];
Perform operations on dataArray on the vc interface, delete an image, and change the images on the pop interface.
The reason is: vc. dataArray = self. images; direct assignment causes pointer address copying and modifying the same object
Solution: vc. dataArray = self. images. mutableCopy; // the address of the returned object is different from the address of the method receiver. Therefore, the addition and deletion of the object does not affect the other operation.
You can also see that the addresses of objects stored in the two arrays are the same, that is, pointer assignment.
So, after vc deletes an image, I use a block operation to synchronously refresh the data on the previous interface, and then the array is out of bounds, because it is equivalent to two delete operations.