I have a variable that is passed between two tableview controllers.The cells in the first tableview have a detail label that is updated by this variable that is passed from the second one. once the string is passed i want it to save and bump out the old string.I would like the variable to stay saved until the app is uninstalled. any idea on how i would do this ? passing the data with protocol. I appreciate any help!
Related
I am drawing a tableview via BehaviorRelay.
Currently, I am using the code below as a way to add data.
viewModel.user.append(Person(name: "king", phoneNumber: "12341234"))
viewModel.personObservable.accept(viewModel.user)
I wonder if this code changes the user itself so that the whole tableView is redrawn.
If so, what method can I use to change only the data I added?
The code presented causes the personObservable (which is actually a BehaviorRelay apparently,) to emit a next event that contains an entire array of Person values, not just the latest Person added. Importantly, it's not emitting the viewModel.user object (at least not conceptually) but an entirely different object that happens to be equal to viewModel.user.
The default dataSource, the one that you get when you call items with anything other than a DataSource object, will call reloadData on the table view. This doesn't cause "the whole tableView" to be redrawn though, but it will cause the table view to query the data source for all of the visible cells, even if they haven't changed.
If you only want the table view to load the new cell, then the data source object needs to be smart enough to compare the new array with the array it's currently displaying so it can figure out which values are different and add/remove/move cells as appropriate, instead of just calling reloadData. As #Sweeper said in the comments, the RxDataSources library contains a set of data source classes that have that logic built in. If you wanted to reinvent the wheel, just write a class that conforms to both RxTableViewDataSourceType & UITableViewDataSource and implement the diffing yourself.
I've got a dynamic table with a cell for a UIDatePicker. There's a function in the UITableViewCell class that updates a variable when the picker changes. I'm just having trouble getting that value back to the UITableViewController class. I can print the correct variable while spinning the picker, but when I go to reloadRowsAtIndexPaths for the tableView I need the value available.
Since there's no segue, I can't get a protocol/delegate to work. I imagine a global variable might also work, but that's cheating. Any suggestions?
You can use NSUserDefaults for storing values globally which can access anywhere into your project. you can set values this way for your picker.
NSUserDefaults.standardUserDefaults().setObject("YouValueForm", forKey: "YourKey")
After that you can access this value anywhere in your project this way:
let yourVar = NSUserDefaults.standardUserDefaults().objectForKey("YourKey") as! String
You can modify this as per your need. and once you got your values you can do reloadRowsAtIndexPaths.
Hope this will help.
I have got information from a URL(JSON); I easily populate my tableView with the text from my dictionary [aCategory objectAtKey:#"names"] for the cell labels. Now, based on the cell name (category), I want to display another table that will ask for the last URL in order to grab the rest of the text, based on that category.
So, i want an ID which is in [aCategory objectAtKey:#"ID"] to save to a string and put in the URL in the next viewController. I am currently trying to generate it using the auto-generated set method to populate the NSString *ID in the target viewcontroller; when i call
[newView setID: [aCategory objectAtKey:#"ID"].
My new view controller's NSString ID says it is not empty, but when i try to check to see if it is indeed "1" or "2" i get something like /p2002 or something. However, in the original class, if i say cell.detailLabelText.text = [aCategory objectAtKey:#"ID"];, the labels correctly show "1" "2" "3".."14" etc....
SO, how can i get that ID from that key into my other viewcontroller class?
I Know it is a valid NSCFString cause i tested it both with isClass AND with the cell's detailLabelText.
I need more detail to be sure about this, but a couple of notes...
NSString is what is called a class cluster, which basically means it is actually a collection of several class different classes that the underlying framework switches between...this means if you are checking it with
isKindOfClass:
you might not be getting the results you are expecting. Check the documentation for isKindOfClass: in NSObject.
However, I am not sure if there is anything to worry about. The reason you are seeing something like '\p2002' (Could the first letter be a u?) could just be the current underlying representation of the string. Sometimes, when the device holds the content of the string in memory, it does not look exactly like "1" or "2". It doesn't mean that there is a problem: it just means that, a deeper level, the way the string is being held in memory is in different form. That is why your label might say "2" but the variable, when you check it in memory, looks different.
(I am guessing that, since you are handling JSON, the string is encoded in a form called UTF-8.) The point is, nothing may wrong at all.
The real question is, is your new view controller loading correctly or not? Maybe in the viewDidLoad: method of your new view controller, if you run something this line:
NSLog(#"%#", stringID);
This will print the value of stringID to the console. If this number is the same as the number of the table cell's label in the previous view controller, everything should have been passed correctly.
I have a UITabBarController that I would like to assign to another object, so that that object can control it:
watchListView.tabBarController = self.stTabBarController;
During this assignment the value of both self.stTabBarController and watchListView.tabBarController are 0x0.
How can I assign the UITabBarController's?
The assignment is (at least syntactically) correct. The problem is that you're doing at a time when the source property has itself not been set.
Without knowing more about when and where this is happening it's difficult to guess what the problem is. At what point are you trying to make this call? Does the controller ever exist? Is there some subsequent time where the property is demonstrably non-nil?
I have an Action Sheet popping up and I want to pass a certain argument to a button processing method.
For example:
I have a table and I want to pass to a button processing method row number that was selected in a table.
How can I achieve this?
You would have to set this in your delegate ahead of time. You can then use this value when your delegate receives the button press notification.
If it is an integer argument, put it as the tag property of the action sheet. Otherwise, you can subclass the action sheet and put variables there, or use associative references.
if you want to pass an integer, use UIActionSheet.tag.
if you want to pass a NSString, use UIActionSheet.accessibilityValue.
these are simple and easy. no need to create an instance variable.