Unable to show popover for a button in xib file - iphone

I have a xib file in which there are multiple buttons. I am able to provide functionality to those buttons except one. For one button, I need to show a popover. I've researched and got results for classes inheriting UIViewController but not for UIView.
In detail, I have 3 files - CustomView.xib (in which there are multiple buttons), CustomView.swift (Class to deal with CustomView.xib) and PopView.xib (which I should load one clicking a button in CustomView.xib)
Can someone please help me with this.

The presentingViewController should be responsible for the popover not the UIView. You can write a method in your custom UIView class to present the popover via the presentingViewController

Related

Scene Dock in Apple's Date Cell Example?

I am looking at Apple's Date Cell (Date Cell Link) example project and I have a question about the Scene Dock in MyTableViewController. How come there are items extra items in the scene (Like Picker and Done) that are next to First Responder, Exit, and My Table View Controller? How can this be done? Also, how is this helpful?
This image shows the Scene Dock that I am referring to. Don't mind the titles, I renamed the project.
This image shows the Scene Outline for MyTableViewController, where the Picker and Done Button are shown next to the My Table View Controller, First Responder, and Exit and not within My Table View Controller.
This image shows an expanded outline for My Table View Controller where the Picker object is found also. But not Done Button is nowhere to be found inside My Table View Controller.
This image shows the code to connect to Picker and Done Button There is nothing special to this.
When I delete UIDatePicker in the scene of the controller (not in the cell), the inline DatePicker still works.
I think this sample is meant to support iOS 6.1 or earlier, to reveal the UIDatePicker as an external slide-in view, so it needs to be in the controller for IBOutlet connection.
Hope this will help.
Normally, the MyTableViewController should not be of type UITableViewController but its superclass UIViewController. This is normally necessary because UITableViewController has by definition its main view property set to the table view. It is then difficult to place other views into this view.
With a UIViewController, however, you can add any number of views. This is necessary in this case to accommodate the button and picker. The table view controller functionality can still be achieved by manually adding the UITableViewDataSource and UITableViewDelegate protocols and overriding the appropriate methods.
However, Apple here shows that it is possible by placing the other views on the same level as the main view, the table view. This is admittedly quite confusing. I usually prefer adding non-standard views as subviews to the view of a plain UIViewController.
You can drag things like picker views from the library to the scene dock to add them there.
As to the utility of doing this, I have no idea what that would be.
In this case I think that the picker and done button are left over from the writers of the code experimenting with ideas and forgetting to delete them. To verify that just delete the picker view and done button and see if everything still works.

facebook type left slide bar layout should appear in all view controllers

I have implemented Facebook type left Slide Bar layout in my first view of iphone app. Now, I want to implement this throughout all view controllers (screens) in application, means irrespective of the view the left slide bar should appear on clicking the menu button at the top in all views.
My app contains 25-30 viewcontrollers and my slide bar layout should appear in all views..
Can anyone suggest, how can I include above FB Layout in all views
Thanks in advance
Ramu
Simple, The one view controller in which you have implemented the FB layout and is working. Make it the base class on top of UIViewController. And as for the rest of all the ViewControllers, inherit them from the MasterClass that you just created. Doing this will make the swipe gesture that brings forth the slide bar available to all of your 30 view controllers.
EDIT
Lets see, we have UIViewController, now first of all you create a UIViewController's subclass: say FBViewController ..In this FBViewController you implement the FBLayout such that the swipe and all is working ..on it ..test your app first using only this FBViewController as rootViewController and check all the functionalities.Once everything is working fine, grow on it. What I mean is this.
Say you are creating a Tabbed application, where all the three tabs are supposed to have the same FBLayout style. Then do these steps.
Create FBViewController, it inherits from UIViewController (using UIViewController subclass template, also check the generate XIB button) also have an XIB for it FBViewController.XIB (fully implement FBLayout in it. This will be your base class)
Then Create three more ViewController classes (FirstViewController, SecondViewController, ThirdViewController) again from the UIViewController subclass template, but for these three dont check the generate XIB button. these three will use the XIB of the base class FBViewController (If you are wondering how, then go to step 3 :))
Go to header file of FirstViewController class you created, there you can see #interface FirstViewController: UIViewController replace it with #interface FirstViewController: FBViewController, but before it import FBViewController.h to the header file. Repeat the same for the Other two classes- SecondViewController, ThirdViewController. Since these three will inherit from FBViewController. In their viewDidLoad [super viewDidLoad] will load FBViewController and generate the view. after [super viewDidLoad]; line you can implement ur own methods.
In the three classes just change the initWithNibName method to change the tab bar name and title.
In appDelegate go to didFinishLaunching method and put these three view controller in a tabBarController, set the tabBarController as rootViewController.
And we are done. If your FBViewController is working fine. You will see that all the three classes behave the same way. Thanx to the power of Inheritance.
Cheers, play a bit, have fun.
I had the same problem. I was using a facebook-style menu, and needed it in all view controllers.
You can use a Container Controller. A Container Controller can have the base layout, which I defined in a nib, containing a navigation bar and a bar button item to toggle the menu, and then add child view controllers and remove them as you need them. That way, you can throw whatever view controller you need to the container controller and it will display it.
You can also add gesture control to slide open/close the menu easily.
You will have to make the Container controller your self, it is not standard. I think it is better solution than inheritance, since if you use inheritance you can't make a for example UITableViewController, all your controllers will be of the type of yuor master class. Of course, you can fix this anyway with delegates.
It may sound a bit tricky, but see this tutorial which I used: http://www.cocoanetics.com/2012/04/containing-viewcontrollers/
It wasn't accutally that hard.
EDIT: You can just use a UINavigationController as well. Just set the base view controller to the view controller you want to display, and you can prevent it adding the back button etc to the nav bar by overriding the default methods. Make a UINavigationController as rootNavigationController. Might be simpler.
I'd highly recommend using an open source solution that handles all the edge cases for you - it's both the easiest, most robust and most maintainable (since the community will keep it up to date fro you). ViewDeck seems to be the most popular solution though I have also had success with PPRevealSideViewController. They both provide a very robust implementation that would take a long time to do yourself (e.g. you can optionally enable swipe on the navigation bar or even content area to open the menu). Furthermore they separate the sliding logic and the revealed menu (which can be any view controller you like, but most likely a table view controller) out of your other view controllers. That way any viewcontroller can have a side menu without duplicating any code - separation of concern is great :)
You can make a SharedInstance for SideView class. I am doing same thing for iAD to show throught-out the application.
Please see the the link of iAdSuite ,In which the BannerViewController is SharedInstance so they are easily used for all View Controller
http://developer.apple.com/library/ios/#samplecode/iAdSuite/Listings/TabbedBanner_TabbedBanner_BannerViewController_m.html

How to make a combo box in iphone/ipad?

This is maybe a simple question, but I don't have a clue the keyword i had to search for this...
I want to create a simple selector (I called it spinner in Android). This is what i want to achieve
Or it will take a whole screen if it's in ipod touch / iphone.
So, I have 3 button that represent filter (category, country, sort) for a ListView... and if I press one of the button, a popover / dialog should be appear to select the filter for each button.
thanks...
Please let me know if I need to add some information to make the question clear.
Its not so much typical that is it appearing.
Create a new UIViewController class with xib and adjust view size you want to display for combo box or popviewControoler. Then put navigation controller over and tableviewController.
And customize your UIViewController using its controller class. Controller class will be reponsible for displaying and selecting data.
Now in your MainViewController From where you want to show ComboBox or popviewcontroller.
declare popViewController instance variable,synthesize it.
implement a userdefined method here alloc your popviewcontroller class and assign it to popviewController instance variable of your class.
Then called it didSelectRowAtIndexPath.
When popover dismiss you set popViewController result in instance variable of this class so it can easily access in MainViewController class.
You can achieve combo box like functionality by adding a UItableView in a UIView and implement all the delegates of UITableView in that custom view.
Now you can add object of that custom UIView where ever you want that combo. Just you have to workout with some Frame setting.

iOS Storyboard How to access the controls and add event handlers, and binding data to controls added on Storyboard

I used to create the UI thru code. But now I have to use storyboard. I am confused about how to add the event handlers to the controls added on the storyboard and how to bind the data dynamically to the controls added on storyboard. A sample scenario is An UIView is added on the storyboard and two UITableViews and a button are added on top of it. I want to add event handler to the button and bind data to the table views. How do I do this. If I subclass the UIView added on the storyboard will I have access to the controls(button, two table views) added on top of the view or how else I should achieve this ?. Please help !
Adding an event handler to a button is relatively simple. In your UIViewController subclass simply add a method similar to the one below, then in your interface builder select the viewcontroller and on the right side panel click the right most button at the top which looks like an arrow pointing to the right. under received actions drag the circle to the button that you want to perform the action.
-(IBAction)doSomething:(id)sender{
//code for doing what you want your button to do.
}
A separate way you could do it, if you still want to do it programatically is to do the same thing you're used to doing, except in your .h file add IBOutlet UIButton *buttonName; and in the right pane under outlets you'll see your button. which can then be referenced by name within the .m file.

NavigationController as a subView

I'm new to iphone development. I have a tabBar App, designes in interfaceBuilder.
When I pressão the About button, it flips to a view where I put the App info. In this view, I need to have a navigaionController with a tableView.
How can I do this?
I'm having a lot of trouble to do this.
Anyone can help Me?
iChat: Rui.Lopes#Me.com
So, I guess you simply want to show a UITableView inside a UINavigationController inside a UITabBarController. This is fairly simple:
First, you should create the ViewController which will contain your TableView. You might have already done this, so just the quick walkthrough: Click "New File" and create a "UIViewController subclass". It's easiest to check "UITableViewController subclass", but a more flexible approach would be to subclass UIViewController and fill it with a TableView in InterfaceBuilder or programmatically. If you need help here, just ask.
Once you created your "AboutViewController", open your TabBarController (most likely in the "MainWindow") in InterfaceBuilder. Now, select the TabBarController, and add a new Tab in the Inspector. Change the Tab's Class from ViewController to Navigation Controller. Inside your newly created NavigationController, there will be a "View Controller (Item)". Select it and, in the Inspector, change it's class to "AboutViewController" (or however you called it). If you created a XIB for your AboutViewController, don't forget to change the value of "NIB Name" in inspector.