Hi, i’ve tried the Part 8: Section 1 Deleting Cells. I got a problem regarding the Unchecked image of the cell. when i’m in editing mode, some of the Unchecked image does not appear when i scrolled down/up. Maybe due to the indexpath for only the visible item of that instant of pressing the edit bar button. is there any way to get indexpath of all available cell instead of visible cell only.
Clicking the Edit button sets the uncheck image visibility for the items which are only currently visible because those are the only ones which need to be immediately made visible. The rest are automatically made visible as you scroll up and the collection view asks for a new image via cellForItemAt:. Look at the code there and you should see this line:
cell.isEditing = isEditing
And if you check the CollectionViewCell class for the property, it should have the following code:
How do you have the IBOutlet defined in your code? You generally are not able connect an outlet if the definition in code is not the same as the type of object on the storyboard. For example, if you have the outlet defined as UIImage in your code but the object in your storyboard is a UIImageView, you will not be able to connect.
So check how the outlet is defined and if you can’t figure out, post a screenshot of that bit of code.
@fahim , I think what @yuan1337 was referring to is the problem when scrolling up and down the collectionView quickly (and the collectionView has more than 1 page of cells, so some of the cells are being recycled during scrolling). Then you will see sometimes, some cells are not being rendered into its editing mode fast enough. Any more leads to this UI bug will be appreciated though.
I realize that @yuan1337 was asking about more than one page of items since otherwise the visible cells vs. non-visible cells bit does not come into play However, my answer to him still stands in that generally the code should work as provided. I tested with more than one page of items and in scrolling the items I did not see the issue mentioned.
Of course, if you have a project which displays this issue consistently, you can certainly upload the project somewhere and provide a link and I can take a look to see what might be going on …
I admit this bug is pretty difficult to duplicate because on the demo app, the cells are not rendering anything too expensive. Anyhow, here is a link to my demo app’s repo, same as the one shown on the video, but with a larger array of data. Also I have a screen shot from my actual device and one from my simulator.
those 2 code seem similar but apparently different because the the second code can’t have nitial value. I think i have problem to understand the basic syntax of this code. so if I want to understand this code, what topic that i should learn first ? what are they called ? it seems like boolean type that automatically changes.
To answer your first question, if you look at the declarations for isEditing and isSelected, while they might look similar, the second one has the override keyword at the beginning. That means that this is a property in the superclass that you are modifying in the CollectionViewCell subclass. So, isSelected actually has a declaration elsewhere which adds other stuff to it that makes it different from isEditing which is something you declared only in CollectionViewCell. Does that make sense?
For the second question, isEditing is a property of UIViewController which is the superclass of ViewController. When you extend one class to create a subclass, like in the case of ViewController (or even CollectionViewCell above) you get (or inherit) all the properties of the superclass.
And if you are ever unsure as to where a property or method is defined when you are looking at code in Xcode, just hover your mouse cursor over the property or method and Command-Click. It should show a menu of choices which allows you to see the original declaration of the element. Or, you can right-click on the item and then select “Jump to Definition”. Or, you can have the Quick Help inspector open on the right, and simply move the cursor over the item and it should show you any available help about the item as well as where it is declared. There are multiple ways to do this
Sorry, been a bit busy at this end. But I did try out your code but still can’t reproduce the issue that you’ve shown in the screenshots. I originally thought that the issue was that the checkmark state is not properly shown. But based on your screenshots, it looks as if the checkmark image is not shown at all in some cases.
That’s a bit puzzling since the image display code executes each time a new cell is instantiated. So if you are in editing mode and scroll, unless the visible cells did not get set up properly for some reason when you switched to editing mode, everything should show the selection indicator.
But since I can’t replicate the issue here, I’m unable to figure out what might be going on. Have you checked running on a device to see if this is perhaps a slow simulator/machine issue at your end?