Beginning Table Views · Deleting Multiple Rows | Ray Wenderlich


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5995-beginning-table-views/lessons/48

Hello, at around 3:40, on line 28 of, when we are creating an array of checklisteItems, why is there a “()” after the declaration and initialization of the array?

The parenthesis is really the constructor. Essentially, this:

var numbers =  [Int]()

Is the equivalent of this:

var numbers = Array<Int>()

By omitting the parenthesis, you are just indicating the type without calling the constructor:

var numbers = Array<Int>

So that’s why we add the parenthesis after the type. I hope that helps!

Dear, @bdmoakley

How can I resign editing session when I press (+) or when I change to a different view? Right now, it seems like I am still in the edit mode when i go back and forth from a add Item view to a main checkListItemView.

46 52

Hey there, what you can do is call setEditing() in your prepare(for segue:). Set it to false at the beginning of the segue and that will reset the table before the new view controller is pushed on the stack. Good luck!

Dear sir,

I got the following error where the indexPath did not have row member.

What are the workaround to this?
Appreciate any help.

51%20PM

For some reason, Xcode thinks you have an array of ints as opposed to an array of indexpaths. It’s a little hard see why that’s happening from this vantage. Feel free to email the project to brian@razeware.com and I’ll take a look.

Did you end up solving this? I have the exact same issues

@hans123dev

Looks like @mkiara called indexPathForSelectedRow on the tableView instead of indexPathsForSelectedRows. The first one will only return a single index path not an array of index paths.
Most likely that’s why you have that error as well.

Hope that helps!

1 Like

Thanks. Yes I did end up finding that mistake eventually.

Hi everyone,
Brain, thank you for the course! :smiley: It explains plenty of concepts and features. It is quite hard for me, but the length of videos allows to rewatch it easily. Thank you very much for your explanations!

I have a question. How can I make the Delete Button enable only when a user is editing the Checklists?

55

I came up with the following solution.

  1. Create an Outlet for Delete button:

@IBOutlet weak var deleteButton: UIBarButtonItem!

  1. Add in the func setEditing(_ editing: Bool, animated: Bool) :
    if editing {
        deleteButton.isEnabled = true
        deleteButton.title = "Delete"
    } else {
        deleteButton.isEnabled = false
        deleteButton.title = ""
    }
  1. Uncheck isEnable and erase Title text of bar item buttom Delete in Main.storyboard

@valeriego Thank you for sharing your solution - much appreciated! :]

2 Likes

Very strange bug with xcode 11.2.1. After lesson 47, when I turn on edit mode and drag my row, after I release my row, edit segue is open up, how to fix it?

Hello ramory-I,
Try this I had same problem so I tried this.

Hello sourav13! Thank you very much! Working for me)

Thank you! Had the same issue. It is still in 13.3.3