where are my UIBarButtonItem & UIToolbar on UIPopoverController - iphone

I have an iphone app, on the top of screen there is an UIToolbar, there are 2 UIBarButtonItem on the UIToolbar.
One is 'Cancel' another is 'Confirm'.
But if I migrate the project to ipad and present the view/ViewController using UIPopoverController, these two UIBarButtonItem & UIToolbar disappear.
I know if I touch anywhere outside the UIPopoverController, it will disappear, but I prefer to keep the UIBarButtonItems to ask for confirmation of some option.
Is it possible?
Welcome any comment
Thanks

The popoverController does not dissapear by itself when you click outsite. The code that makes it dissapear is:
if([self.popoverController isPopoverVisible])
{
[self.popoverController dismissPopoverAnimated:YES];
return;
}

Make sure you have added the UIToolbar to the viewcontroller's view before presenting it in the popover.

Related

MPMediapickercontroller tab bar overlap with custom tab bar in iPhone

I can hide or unhide tab bar in navigation controller. But issue when I use presentModelViewController of MPMediapickercontroller, and even when hiding custom tab bar, it overlaps the tab bar of MPMediapickercontroller.
Please take a look at this image.
This is a default 'MPMediapickercontroller' presented.
I have been surfing to find this fix but with no success.
In MPMediapickercontroller its always present modally. so one solution for that is you have to use image which is same as tabbar of MPMediapickercontroller.
Here is that image. use without any border just white image thats it.
Now, below is my code.
In Viewwillappear method you have to set that image in tabbar appearance.
-(void)viewWillAppear:(BOOL)animated
{
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"tabDefault"]];
[super viewWillAppear:YES];
}
Then whatever you want presentModelViewController of MPMediapickercontroller
in last you done all things then you have to use dealloc method to set Tabbar same as you required permanent.
-(void)dealloc
{
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"tab2"]];
}
I solved my problem from this. hope you done it.

UIPopoverController not dismissed when opened from self.navigationItem (inside UINavigationController)

I have a problem dismissing a popover that was launched from the navigationItem of a UINavigationController. It seems that the navigation item which is inserted by the UINavigationController does not trigger dismissal of the UIPopoverController. Usually, when you tap outside a popover, it is dimissed. But when you tap on the navigation item, the popover is not dismissed. Worse, if you tap the button which triggers the popover, you'll get a second instance of the popover.
All of this is done using storyboards:
- Create a view, embed it into a UINavigationView so it gets a navigationItem on the top.
- Put a UIBarButtonItem into the navigationItem (left or right, doesn't matter for the initial view on the navigation stack).
- Define another view, and drag a segue from the UIBarButtonItem to this view.
- Set the segue to be popover.
Once the popover is open, I cannot dismiss it by tapping on the navigationItem. I cannot believe this "works as designed", so I suspect I missed out on somthing.
Although my goal is to program as little as possible (that's what storyboards are about, aren't they?), I thought about workarounds: The first workaround that came to my mind was to add a UITapGestureRecognizer to the navigationItem, which would dismiss the popover when it detected a tap on the navigationItem. Unfortunately, the navigationItem seems to not be UIVIew, so it lacks the addGestureRecognizer: method...
EDIT: Adding a UITapGesturerecognizer to self.navigationController.navigationBar is possible, but prevents any tap to reach the UIBarButtonItems on the navigationBar. Yes, I could have expected that.
Thanks a lot for help,
nobi
Here's the complete description for popovers in storyboards. Assuming your controller to appear in the popover is named MyPopupController, do this:
Define a segue from the main scene to the MyPopupController scene, using style Popover.
Add a property to MyPopupController.h
#property (weak, nonatomic) UIPopoverController *popover;
Synthesize the property in MyPopupController.m
#synthesize popover = _popover
In the prepareForSegue:sender: method of the main scene controller, set up the popoverproperty:
UIStoryboardPopoverSegue *ps = (UIStoryboardPopoverSegue *)segue;
MyPopupController *dc = ps.destinationViewController;
dc.popover = ps.popoverController;
In the viewWillAppear: method of MyPopupController, add the following code (don't forget [super viewWillAppear] as well):
self.popover.passThroughViews = nil;
You should be done now.
Thanks to Robert for the basic idea - I just had to find the correct place because presentPopoverFromBarButtonItem is not used when using storyboards. Note that putting (5) into viewDidLoad does not work.
Have fun coding!
https://stackoverflow.com/a/12874772/1455770
after presenting a popover from a bar button item, the popover has had its "passthroughViews" set to include the nav bar, so your taps don't register. Set the passthroughviews to nil straight after you present the popover. ie.
self.myPopoverController presentPopoverFromBarButtonItem:myBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.myPopoverController.passthroughViews = nil;// at this point the myPopoverController has had its pass through views set to include the whole nav bar. remove it.
There might be a better solution than this, but why not only add the UITapGestureRecognizer to the navBar whenever the popover is open? Once you tap the button to open the popover, add the TapGestureRecogniser to the navBar. Once you dismiss the popover, remove the TapGestureRecogniser from the navBar.
I've faced this problem recently and none of the solutions that I've seen around worked for me. Then after some research I've found out a way that works like a charm.
First you need to add the UIStoryboardPopoverSegue to your class.
#property (nonatomic, strong) UIStoryboardPopoverSegue *popoverSegue;
Synthesize it inside of the class implementation:
#synthesize popoverSegue;
Afterwards, inside of the function called by your button when pressed add the following code:
([[popoverSegue popoverController] isPopoverVisible]) ?
[self.popoverSegue.popoverController dismissPopoverAnimated: YES] :
[self performSegueWithIdentifier: #"popSegue" sender:nil];
Now you are almost ready. inside of the method
- (void) prepareForSegue:(UIStoryboard)segue sender:(id)sender add the following code:
if([[segue identifier] isEqualToString:#"popSegue"]){
self.popoverSegue = (UIStoryboardPopoverSegue*) segue;
if(viewPopoverController == nil){
viewController = [[UIViewController alloc] init];
viewPopoverController = [[UIPopoverController alloc] initWithContentViewController:viewController];
}
}
Now every time you press the button it will either show or dismiss your window, the window will also be dismissed if you press outside of the popover. I hope it can help someone.

How to add NavigationBar and button in UIPickerView of iPhone Programming?

I would like to ask a question.
Now i'm training about iPhone Programming.
I'm just new baby in iOS Programming.
I want to add navigationbar in UIPickerView's upper place.
It's like the UINavigationBar in MainView.
I just want to add on UIPickerView.
and also i want to add Done button in that NavigationBar.
After i touched that done button, my view will back to main view.
How can i do that?
Please answer me if you know.
I hope you understand my question.
Sorry for my bad english.
Thanks you for reading.
All you do is drag a navigation bar on the top of the uipicker. Im assuming your wanting this UIPicker to popup, so just create a view just for the picker, drag in a navigation bar and uipicker into the view, then adjust the size of your view window for the bar and uipicker. THen you just need to hookup the the bar and uipicker to file's owner as delegates. Make sense?
When I understand you correct, you have one navigation controller and want to add to this navigation controller a new UIView with a UIPickerView which comes up after pushing the edit Button and hide when you press done button?
Then I would create a new UIViewController in Interface Builder, add the UIPickerView to this View. Put this in the correct place. In the new view controller add a property of type UIPickerView and connect the IBOutlet of PickerView to the FilesOwners Property. In the Controllers method viewDidLoad you set then for example:
[self.datePicker setHidden: YES];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
This button calls automatically the method setEditiong: on pushing. You can reimplement it for example:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (editing) {
[self.datePicker setHidden:NO];
} else {
[self.datePicker setHidden:YES];
}
}

PopOver in a UItabBar

I need to create a popover in a tabBar in the right side of it.
Like the:
self.navigationItem.rightBarButtonItem
property in a navigationBar.
(Forget the other buttons, i just need one button.)
Any idea of how doing this??
Thanks
If you want a popover to appear over a tabbaritem you could look at my answer here: UIPopoverController placement

UINavigationController Toolbar Buttons

I have a UINavigationController that I've set as the rootViewController of my window. In the NIB file I've set it up so that it has a "Bottom Bar" of "Toolbar". In Interface Builder I've added a UIBarButtonItem. This all works great and I can handle the button click fine. When I hit one of the buttons, I push a new view onto the ViewController and that works fine too. One problem, my button disappears when the view is loaded. Now in the subsequent view I can set the bottom bar to be a Toolbar and I see it in Interface Builder, but I cannot add any buttons to it.
I know I'm either missing something obvious or thinking about this incorrectly but how do I add UIBarButtonItems to subsequent views pushed to my nav controller? I'm talking the bar at the bottom, not the nav bar at the top.
Any ideas?
The toolbarItems property on the UIViewController is what you are interested in. You can create UIBarButtonItems programmatically and add them to a new toolBarItems array in viewDidLoad.
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem* editButton = [[[UIBarButtonItem alloc] initWithTitle:#"Edit" style:UIBarButtonItemStyleBordered target:self action:#selector(editAction)] autorelease];
[self setToolbarItems:[NSArray arrayWithObject:editButton]];
}
This worked better for me:
[[self navigationItem] setLeftBarButtonItem:homeButton];
You can do the same for the right side.