This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5429927-beginning-collection-views/lessons/20
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5429927-beginning-collection-views/lessons/20
Hi, this is a simple question but made me think. When I delete all the items of a section except one, this item is centered on the screen horizontally. Is this behavior normal? And is there a way to change it so it is aligned to the left?.
@optastudent Nice find! Iโm tempted to say this is a bug. Iโll try and replicate this on my end and find a fix. Meanwhile I found this Stack Overflow thread that has a solution
@pasanpr, when we override setEditing func we switch on delete button and off add one. How are they toggled back again since we do not do it intentionaly in code?
These are the lines of code that toggle the buttons on and off:
deleteButton.isEnabled = isEditing
addButton.isEnabled = !isEditing
When we tap on the edit button, isEditing
is true
which enables the delete button by setting deleteButton.isEnabled
to true
and the hides the add button by flipping its enabled value to false using the NOT operator.
Similarly when we tap on the done button, isEditing
is now false
and toggles the respective values on each button.
@pasanpr, does that happen because isEditing is a property of a class (not a struct)?
@pasanpr Can you please help with this when you get a chance? Thank you - much appreciated! :]
It doesnโt necessarily have to do with being a struct or a class. You could achieve it with both. When you tap on the edit button one of the actions it executes is to set the value on isEditing
to true or false depending on the state. Since weโre observing the value of isEditing
to set our button properties, tapping the button triggers it.
In this particular case the view controller is a class but this is also possible with a struct (in SwiftUI for example!)