UIPicker and UITableView in iOS - objective-c

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.

Related

why IB sometimes doesn't add a subview to a view controller

Sometimes IB simply doesn't allow you to add a view as a subview to a UIViewController as illustrated here
If I drag a UIViewController from the object library and try to embed it within Mailbox View Controller.. it doesn't highlight, however it would work fine if I try to add it to the generic View Controller at the bottom (can the fact that Mailbox View Controller have a Customer Class MailboxViewController have anything to do with it?)
I'm pretty sure I can do this programmatically (which is what I'll try next) but I was wondering if there was a reason for this (and if there was a way around it).
update:
this is what i'm trying to accomplish: I was following the steps here to implement a segmented view controller below search bar like in the iphone mail app.. however I kept on getting an error saying that a view can only belong to one view controller at a time.. So what I'm trying to do is basically create a separate viewcontroller, reference it from MailboxViewController as an outlet, make the containing view of my search area the view of this new view controller (this is where i'm getting stuck) and finally make the searchContentsController property of UISearchDisplayController refer to the view of this new view controller. (if this sounds confusing, which I know it does, please refer to this answer)
From your screenshot, the view property of your mailbox view controller is a table view.
A table view in interface builder won't support the dropping of arbitrary views onto it as subviews - where would it put them at runtime? In IB the table has no content, it just has that visual representation of cells to let you know what it is.
You haven't said what you are trying to set up so I can't offer any additional help. Adding a subview programmatically to a table view probably won't give you the effect you're after either - a table view is a UIScrollView subclass, so your new view will either move off screen or get covered up by the table view adding cells.

Create UIPopOver without including Tableview in ios

I want to create two PopOvers when at the time button clicked and textField clicked in the same UIView (not ViewController). In those popovers I need to load separate array values. Is there any way to create them and added to UIView?
I already added one tableview for base UIView, so without using tableviews, how can I create UIpopOvers and load the arrays in those popOvers? How to handle the selected rows?
This link can help you to create a popover menu.
Or you can take an UIImageView having shape of popover menu and table view in that, it will be easy to load arrays and to handle selected rows.
I did the same using second method.
Happy Coding!

Showing Toolbar on 2nd ViewController

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.

How to access Navigation Bar from a View Controller of a subview ?

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.

Add other objects to iOS 5 storyboard after tableview

I have a simple iOS 5 storyboard that contains a tableview controller scene. However, the table UI takes up 100% of the real estate and I am unable to add any additional objects such as a title bar. Any object that I drag to the scene will try to size correctly and what-not but as soon as I let go it will not add the object. What am I doing wrong?
If all you want is a title bar, then it looks like you want to embed your table view controller in a navigation controller. You can do this by selecting your table view controller and using the Editor: Embed In: Navigation Controller menu command. Once you do this, you should have a navigation bar, and you can double click it to edit the title.
If you need arbitrary UI elements along with your table view, then I think you need to use a plain UIViewController scene instead of a UITableViewController, and manually drag a UITableView into the scene. Your view controller would not subclass UITableViewController, instead it would subclass UIViewController and implement the UITableViewControllerDelegate and UITableViewControllerDataSource protocols. Also, you would need to manually wire up the delegate and dataSource outlets by ctrl-dragging from the table view to your view controller in interface builder, and your view controller would need a custom tableView outlet that points to the UITableView and is correctly wired up in IB. Perhaps there is a simpler approach than this though, if someone has a better suggestion that would be great to hear.