UITableViewController and Auto-updating Results - swift

I'm currently developing and iOS app in Swift 2.0 and I'm running into the following issue:
I have a custom query that fetches a list of items that populate a UITableView. When tapping the cell I get the ( values[indexPath.row] ) Object and segue it to another view controller for display as well as the list of items (for other actions like swipe to move to the next one).
My issue comes from a background process that fetches periodically new data and saves it to Realm.
Since Realm keeps all nice and updated, the indexPath.row will fetch a different value (the list of values has changed in the meantime due to the automatic updater) resulting in showing something that is not quite what was tapped.
Both Realm and the updater are working, but this results in a confusing experience for the user.
Am I missing something obvious?
Thanks a lot for the help!
PS: I've looked also at ABFRealmTableViewController, but I'm not displaying the whole data but a filtered (and ordered) subset.

Probably the easiest way of preventing this issue is to observe notifications sent out by Realm whenever a write transaction (i.e. an update) occurs and update your UI accordingly:
// Observe Realm Notifications
let token = realm.addNotificationBlock { notification, realm in
viewController.updateUI()
}

ABFRealmTableViewController supports filters via NSPredicate and sort descriptors as well. So you might want to give it another try.

Related

How to proper update table cell info if data was changed in another tab bar controller?

Good day! I really don't know how to ask google for my problem to find good solution. Please help! I have got tab bar controller with T1 and T2 vc. T1 is tableview controller and it shows posts(cells) with like button. So e.g. i look at some post and go to T2 vc. There, i (somehow) navigate to that post and like it. Now if i return back to T1 vc i want that post would be liked. How to do that?
1) I thought about create global array with liked posts and create some update loop in cell to check that array and update data.
2) Or create some delegate methods. But i think it's complex.
If you have some experience in that things, please help. Scheme
Most larger apps will solve this by having at least one service that servers as a single source of truth for some kind of shared data. Each VC then subscribes to this service and updates itself whenever the central store is updated. Examples of this are using CoreData, Realm, or Firebase (all of which allow you to subscribe to changes in a query). If you have a simple app you can implement this yourself by posting your own custom Notification whenever your data changes.

RXSwift Update single element

Considering I have a array of items which might be updated on a different view controller and get notified update the change.
How can I update a Observable<[SomeObject]> with a single SomeObject modification so the change will then be propagated to the UITableViewController that presets these items?
P.S.
I can load the whole thing again with some hack, but it's obviously wrong for various reasons.
Thanks.
The short answer is, you can't.
However, if you change your model, there are several ways you can go about doing it. One example is here: https://github.com/dtartaglia/RxMultiCounter
In RxMultiCounter, I populate the tableView with an Observable<[UUID]> and track the changes for each item inside an Observable<[UUID: SomeObject]>. Updating the latter observable doesn't cause the tableView to reload.

How to get user input with UITextView in different cells in UITableVIew

so I have a UITableView and within each cell, a UITextView. I want the user to be able to edit each UITextView as many times as they like, then go back to somewhere else in the app, close the app, whatever, and then come back and see the same thing they wrote. I have not been able to figure out how to do it.
Please help. I'm still pretty new to Swift.
This is a design problem. Anyway my suggestion is to add a flag in your data model.
Data model (the data that you are presenting in your table). If you don't have any data model, add one.
Example:
class UserInformation {
name: String
isEditing: Bool = false
}
and then save this in your preferred location either in DB (core data, realm etc) or plist (which i don't recommend)
now during the creation of cell. You could just check if this is in editing mode. And then fill up the text field using the saved data.
EDIT: You can't just magically know/retain a state in an object without persisting.
You want to store textView informations in any case, including terminating application, there are some steps to implement this feature.
At first, you have to pick up a place for storing your information:
Hard disk
Your own server
Other service (firebase ...)
RAM is not useable in this case.
Supposing you like hard disk option, let's select a method for storing:
Create a file (JSON, text file, ...), save your information every time user enter a new one, open it to get information back.
Save it by CoreData / Realm in database way (CoreData is like SQL lite, a lite weight database for mobile application supported by Apple)

Applying user-entered data in one view to a second view

I'm trying to write an iphone OS app that includes a logbook feature. The problem that I'm having is that I want each new logbook to have its own categories that are user-defined, for example a chemical receipt log would have chemical name, vendor, receipt date, expiration date and comments.
The way that I'm trying to go about this is by calling an editCategory view controller when a new logbook is created that contains a number of UITextields where the user can enter the categories. I want to take those strings and apply them to a newLogEntry view controller, so that when the user creates a new log entry, they are presented with each category followed by a UITextfield so they can enter the relevant data.
The trick is, I have no idea how to grab the category data from editCategory and apply it to newLogEntry. I'm currently using Core Data, as that seems to be the easiest way to go about this, but I'm not married to it if it interferes with a good solution. Also, I'm still more comfortable with genetic code than objective-C code, so please bear with my ignorance.
Have you considered using the App Delegate? You could keep those values in the App Delegate, and call on them in the ViewDidLoad method of your newLogEntry view controller.

save checked items in table view for later reuse in iPhone

Got a conceptual question: If I got a tableview with about 100 items and the user can check as many as he wants from that list, how and where do I save the checked status of each individual item for later reuse?
In your own internal structures. UITableView isn't a database. It merely is an interface to your data. Any selection, deletion, addition, etc. will have to be handled by your code and stored. Typically you have some sort of a database or structure associated with the UITableView elements. When you get a check action, you can update a variable in that structure.
For an example of an SQL database backed UITableView app, see here.
For storing the checked elements of tableview, you have to maintain your code in didselectRow mthos of tableview. So, whenever you check the tableview row you can save it in an array. And save that array in the "NSUSerDefaul". So, that whenever you close the application, you can get back your selected tableview row array from "NSUserDefault". Or you can use sqlite database but it is better to use NSUserDefault as there is simple thing to do.
Please give your response if you find any problem.
You can use NSUSerDefault in your application from the following link: click here