Entering data directly via table view swift 4 - swift

I’m having a play about with table views and saving data. I’ve managed to created an add button where you can add some data to a table view (like a to do list app) and it saves in user defaults. However, I can’t seem to figure out how to add and save data directly just by pressing an empty row in the table view. Basically, I would like to know how to add data and display data on a table view just like the stock To Do and Reminders app from Apple.
I’m working with Swift 4.
Any help or code examples would be much appreciated!

Related

presenting form input into a table view

so I am trying to show a table view of booking slots and the details the user have chosen, I have tried linking an add button to the form using a segue but have failed (it was the question I have previously asked)
Hence, I was thinking if this would be feasible and how I can do it
form input will be shown on another vc eg "u have successfully booked (date) and am slot)
I will get my data there to be shown in the table view
would that be feasible how can I do that? also I have used firebase Firestore database
or any references I can refer to that u guys know of?
THANK YOU

Preserving (and loading) table view scroll position for each data source

I am trying to replicate Mail.app behaviours in my app. If you have multiple e-mail accounts and select a random e-mail for each account and switch between each account from the sidebar, the app remembers your scroll position and which e-mail you selected and display them accordingly. That is what I want in my app.
I know how to preserve the row selection, that is easy. tableView.selectedRowIndexes
My tableView has multiple data sources and switches (tableView.reloadData()) accordingly from the sidebar.
I am having a major problem with the scroll position. I tried looking into NSScrollView, NSClipView and NSTableView. It seems to me that there are scrolling mechanism for each view.
I need to remember the scroll position when the user scroll for each data source
I need to load the previous scroll position when the user return to the data source
Also a strange behaviour I noticed is when reloading tableView to a different data source, it seems to persistently remember from the previous data source scroll position. Is that normal? I assumed it would reset to the top.
My data sources are arrays which are my NSViewController subclass properties.
If it matters, I am using storyboard, my app is targeting Big Sur and I am using Swift.
The position to save:
preservedPosition = tableView.visibleRect.origin
Restore:
tableView.scroll(preservedPosition)

Saving the state of my UITable View

i have a checklist that is on a UITable View. The user can add/delete cells and check them and uncheck them. I need some assistance with saving the state of the checklist when the page is left, becuase when the user adds a new cell, leaves the page, and returns, the table view is back in the original state i had made it be in! Does someone know my problem? Thanks Guys :D
-Kurt
What you appear to be missing is that adding or deleting a row from your table does not update your source array. Typically when working with a UITableview there are three steps you must perform:
add or remove the tableview cell
update your source array (presumably adding or deleting objects in your context)
save your context to commit the changes
This is assuming you are using Core Data for persistent store. If you are saving in memory than you are likely done at step 2.
I suggest you review the UITableView Class reference, look over the examples and step through a tutorial before trying to stumble through the process.

Need architecture direction

I'm creating an app and I need some help with design.
Launch Screen - I want to show 6-8 "category" buttons with labels loaded from an array ("normal" buttons from interface builder - not tab bar buttons or menu bar buttons).
Table Screen - When one of the category buttons is pushed on the launch screen, I want to show a table view with all of the items in that category.
Detail Screen - When one of the items on the table screen is selected, go to a new screen with details for the item. There will be an action button on this screen which will remove the item from the list if pressed.
My questions are as follows:
1) I don't want to show navigation buttons on the first screen. Can I still use a Navigation-Based application and hide the navigation controls on the first screen, or would it be better (easier) to create a view-based application and put a navigation controller "inside" one of the views? I'm totally open to any basic design approach suggestions you may have.
2) I've figured out how to create a sqlite3 file, add it to the project, query it, and generate the table view from the results, but I'm not sure about how to store the sqlite file in a way that will persist on the device when the user upgrades the app later. Any pointers on that?
Thanks for any help/links/documentation you can point me to. I've watched a million tutorials but none of the ones I've seen really address basic app design.
Now for Q1, both ways work fine but if you have buttons from the first screen, having a uinavigationcontroller might make it slightly easier if you plan to have back buttons on the screens after the first screen.
For Q2, to make the database persist when the user updates their app at some stage, simply keep the original database and include a new database (with a different name) with additional content, then modify your original database and import any additional content to it.
You can also do variations of that also, ie import content from old database to new database and etc. But the key is to keep the database file names different, ie add database_v1.sqlite, database_v2.sqlite and etc.
BTW don't forget to clean up any databases you won't use in future.

My data source is being changed out from under a UITableView

I have an app based on a tab bar and data retrieved from the Internet. The main tab shows a map and one of the other tabs shows incidents around the center point of the map displayed using a UITableView. If the user moves the map and then moves to the incidents page, I need to refresh the list of incidents displayed in the table. To do this I request the incidents in viewWillAppear:animated: and when that completes (asynchronously) I call the table view's reloadData method.
This works beautifully unless the user taps between the tabs quickly (e.g. display incidents, move to map, move map, move back to incidents, move back to map, etc.). At some point the incidents data source (an NSArray) is modified while the table view is trying to access it.
Here is a question that is similar:
UITableView Crashes if Data Source Is Updated During Scrolling
One of the solutions for that question describes a solution at a high level that is exactly what I want: Freeze the data source while the table is being updated. The thing I can't figure out, however, is when to unfreeze the data source. The problem is I can't find any way to be notified when the table is done being updated.
Any ideas? How do I freeze the data source while the table is being updated and then unfreeze it once the table is done being updated?
Although I'd really like to receive a notification when the table view is done accessing the data source, I found that my problem was due to modifying the data container from the work thread. The answer to this question led me to the solution:
Refreshing XML data and updating a UITableView
What I do now is fill a separate array in the worker thread and then perform a selector on the main thread to swap the updated data into the data container used by the table view.
The problem is I can't find any way to
be notified when the table is done
being updated.
I think you can assume that the data is done being loaded by checking in tableView:cellForRowAtIndexPath: to see if the last row has been loaded.
I haven't tested it, just making an assumption based on the API