Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update Data in tableview using swift?

Currently I have 3 swift files: ManualViewController, AutoViewController, Main

ManualViewController is the UIViewController with a table view. AutoViewController is a UIViewController with a few buttons. Main is just a swift file with all the data for table view.

ManualViewController and AutoViewController are controlled using TabBarController.

When I run the app the initial contents found in Main.swift is loaded onto the table view. When I go to the next view i.e AutoViewController and click on a button to change data in Main.swift, the data changes. The problem is when I switch back to ManualViewController the table still contains the old data and not the updated one.

I also tried this:

override func viewWillAppear(animated: Bool) 
{
    super.viewWillAppear(false)
    self.tableView.reloadData()
}

It still din't work.

like image 591
Rakshith G B Avatar asked Jun 25 '15 07:06

Rakshith G B


People also ask

Can you update a table view?

The SQL UPDATE VIEW command can be used to modify the data of a view. All views are not updatable. So, UPDATE command is not applicable to all views. An updatable view is one which allows performing a UPDATE command on itself without affecting any other table.

Can we use Tableview in SwiftUI?

In this blog post, I'll introduce the collection view Table in SwiftUI and explain how to leverage this view on iOS 16 to build a multiplatform app. SwiftUI provides several collection views that you can use to assemble other views into dynamic groupings with complex, built-in behaviors.


1 Answers

Under normal circumstances, the way to update data in a UITableView is

self.tableView.reloadData()
like image 155
Suragch Avatar answered Sep 23 '22 05:09

Suragch