Swift UITableView - Insert and Delete Rows - Tutorial

Sean Allen · 44K views · 2017 · 8:13

Open on YouTube

Software (other)Python, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering UITableView questions about deleting or inserting rows and index-out-of-range errors, as a worked example to follow.

Recommended by 2 people across 2 different months, 2019 to 2020.

What it is

A short Swift tutorial by Sean Allen showing how to insert and delete rows in a UITableView in Xcode, updating the underlying array and the table together. The description notes that beginUpdates()/endUpdates() are only needed for batched changes.

What people said

Recommends Lou Franco · 2019-06 · Stack Overflow · on “Fatal error: Index out of range, Due to pressing like and heart button again and again”

I recommend that you 1st get everything working with reloadData() -- then go read the apple docs for [LINK] and [LINK] and [LINK] and maybe watch this tutorial: [this video]

Recommends nicksarno · 2020-05 · Stack Overflow · on “IndexRow variables in collection view cell does not change after reloadData()”

It looks like you may be creating a new instance of UserControllers() when you call the following line. let UC = UserControllers() Instead, try passing the UC directly... var userCont: UserControllers! func setupIndex(_ indexRow: Int, _ userControllers: UserControllers) { self.indexRow = indexRow self.userCont = userControllers } Then in the delete function, call userCont.deleteSocialPlatform... Otherwise, I would check out this link [this video] which covers how to delete rows in a tableview efficiently. Let me know if this worked?

Cites Lou Franco · 2019-06 · Stack Overflow · on “Fatal error: Index out of range, Due to pressing like and heart button again and again”

Why do you do this on succes? self.activityArray.removeAll() The next time you call this function, you index into the array "activity_id": activityArray[sender.tag].id! But it will be empty based on the code you have shown If activityArray is changing and it appears that it is used for the table rows, you need to call tableView.reloadData() to empty the table Edit -- after seeing updated code. You have a few things wrong You remove the data before you know if you have new data You are reloading data in a background thread -- it always needs to be in the main thread So, Delete the line self.activityArray.removeAll() in liked(sender:) Add that line here if response.result.isSuccess { let Activ

Cites RomaRobot · 2020-06 · Stack Overflow · on “Swift. Why doesn't work UITableView delegates?”

You're right, but why in the first example its also works without init of delegates? I used this example. link [this video]