The group assignment problem occurs when values are passed in the interface. The interface transfers array assignments.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.