When I launch the app in question I load up a table from an array derived from a plist. In didSelectRowAtIndexPath I assign values from the array to sub views in detail view controller and then push the detail view controller onto the stack, but when running the app, the first time I select any row from the table, data from the array does not appear in my detail view controller's subviews/fields. I then click back to the table view, re-select the row and the data then loads in the detail view controller.
In the table view controller didSelectRowAtIndexPath method I do the following where xLabel is the UILabel sub view in the pushed view controller's xib:
self.detailViewController.xLabel.text = [[[xArray objectAtIndex: indexPath.section] objectForKey:#"xDesc"] objectAtIndex:indexPath.row];
What do I need to do to have the data appear the first time a row is selected?
I think this is not working because first time when you select a row your detail view controller is not there in memory stack, so you can not call setText method of a label in previous view controller. Second time its working because its there in memory so you can call set method to its component. What i want to say it that when you are pushing detail view controller in stack just set a string of detail view controller here (this string should be property of detail view controller) and then in detail view controller's viewDidLoad method set the text of your label to this string.
If i understood you correctly, there is no xLabel object the first time around as it will be created when the UIViewController is being "loaded". So, when you try to set the text value, it isnt loaded into the label, as there is no label. Subsequent attempts work as the label is created from the first attempt. Anyways, if you need to share some data with the detail view, store then in a dictionary or some other object rather than just assigning it directly to the view from the current controller.
Related
I have two view controllers on the same storyboard. What I want to do is send an array of string values to the table view control on another view controller.
ViewController2 *second=[self.storyboard instantiateViewControllerWithIdentifier:#"View2"];
second.arrayFromVC1=areaArray;
[self presentViewController:second animated:YES completion:nil];
The second view controller has a toolbar control at the top by default. (See below.)
Passing data to another view controller wasn't easy for me, who has been using Xcode for two weeks. I somehow managed it. So an array of strings is sent to the 2nd view controller through an array variable (arrayFromVC1) set on the 2nd implementation file. I suppose experienced Xcode users know what I'm talking about. Anyway, the 2nd view controller does receive a list of values as shown below.
Well, the problems are that the toolbar control on the 2nd view controller will disappear when the user gets to see the list and that the table view control (UITableView) occupies the entire window. I understand that you can control the size of the table view control by specifying values under the viewDidAppear method. But my question is... Is that how things work with iOS and Xcode? So if I want to display that toolbar control at the top, I have to do it programmatically by writing code under the viewDidAppear method as well?
Thank you for your advice.
Tom
Tom, are you using interface builder and storyboards? If so, select the ViewController in IB, go to Editor (in the top menu) --> Embed In --> Navigation Controller.
This will embed the chosen VC and any VC it segues to (and so on) into a Nav Controller.
I am new to iOS and confused about the right way to implement UIPickerView.
I have a UITableView (the list of which is populated by XML File). Now I want to implement an option to trim down that list (say, show only type X or type Y). Now the confusion is, should I implement the PickerView in TableView itself, or make a new segue to show PickerView.
I tried implementing the first one but couldn't get it working.
A picker view wouldn't really fit inside a table view. You should have a button on the navigation bar or toolbar on your table view controller which presents a modal view controller holding your picker view.
This would then feed the selected value back to the table view controller (via a custom delegate protocol method, or similar) and the table view can filter its rows.
I have a View Controller where I select some data into an array and then optionally on clicking of a button I show that data in a TableView added as a subview to previous view with a flip animation.
Now I have the facility to delete data from array I have picked from first view and passed to this one.
Now I have a condition that there is a button on the righthand side on the navigationBar on whose controller the previous view was pushed.
Now that button needs to be disabled until there r atleast X number of elements in the array.
so while I am adding data In my previous view, I keep check on the array and as soon it crosses the required count , I enable the button.
Now in the other view which is a TableView which has been brought in with animation,
Whenever I delete data I need to disable the button again when it goes below the number X.
How can I access the navigationBar's button in this subview's controller ?
shall I set the first view Controller as delegate in the next one ?
If your viewController is inside UINavigationViewController, you can set navigationBar buttons with self.navigationItem.leftBarButtonItem and self.navigationItem.rightBarButtonItem.
try using superView proprty or loop through all the pushed ViewController and check if it is previous VC. Then make the button enabled or disabled
My opinion is you can create a uinavigationController object in your subview and assign it from your parent view(Where you have the navigation controller object). You can then access the navigation controller in the subview.
I am trying to implement a popover view in a tableview controller. My intention is for the user to select an option from the table list as shown below.
Note that my popover view actually displays the data from a separate table view controller. I am creating the popover view controller via the following initialization method
self.popOverViewController = [[UIPopoverController alloc]initWithContentViewController:optionsTableViewController];
After the user selects an option for example "Hottest All Time", the control should be passed from the tableview Controller (in the popover view) back to the MAIN table view controller (parent view) so as to trigger a table reloadData method.
Query: Is there a way to return the control from the tableview controller in the popover controller back to the MAIN tableview controller?
Do I have to use a delegate method to do this?
The two approaches I've seen are roughly the standard sort of fare:
create a delegate protocol for the class type of optionsTableViewController, have the controller that creates the popover implement it and set itself as the delegate when issuing the popover
use the NSNotificationCenter (which actually fits the intended purpose of the thing if you've a one-to-many message, as may be the case if you've a popover with a setting that affects a bunch of different controllers and you don't really care which is visible when the user requests the popover)
I have a UITableViewController which in it's tableView:didSelectRowAtIndexPath method, sets up a view controller, and calls
[self.navigationController pushViewController: viewController animated:YES].
When i select a row in the root controller, the second viewController loads but is empty - table view loads but has no data. Here, tableView:numberOfRowsInSection is not called.
When i return to the top level, and then select the same row again, the view loads correctly - method called.
Why would the table view not call the delegate methods on the fist attempt, but call them on the second?
Am i missing something obvious?
Thanks
Solved by using initWithNibName instead of initWithStyle - knew it would be something obvious.
Thanks
When you say:
When i select a row in the root
controller, the second viewController
loads but is empty.
Do you mean that the view is present but contains no data or do you mean that the table disappears to be replaced by blank/empty view?
If it is the former, then you need to make sure that the second level view controller has proper access to the data before you push it on the stack so that it can populate its view.
If it is the latter, it sounds like your second level view controller is not properly initializing its view the first time it is called. If you use a nib, check in Interface Builder that the controller has an outlet pointing to the view. If you create the view programmatically, check that the view is being initialized properly before it is called to display.