iPad UIPopover presented over UIBarButtomItem covers BarButtomItem? - ipad

I have UIBarButtomItem that shows popover when pressed:
//add help button
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Help", #"Help") style:UIBarButtonItemStylePlain target:self action:#selector(showInfoBubble:)] autorelease];
infoBubblePopOverVisible = NO;
self.infoBubblePopOverController = nil;
Here is show info bubble:
- (void) showInfoBubble: (id) sender {
[self dismissPopoverControllerExplicitly];
if (self.infoBubblePopOverController == nil) {
InfoBubbleViewController *controller = [[InfoBubbleViewController alloc] initWithNibName:#"InfoBubbleViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
self.infoBubblePopOverController = [[UIPopoverController alloc] initWithContentViewController:navigationController];
[controller release];
[navigationController release];
}
//present popOverController
[self.infoBubblePopOverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
infoBubblePopOverVisible = YES;
}
But when presented popover is presented partially covering barbuttomitem:
How can i fix this?

Related

iOS - [ObjC] NavigationBarButtonItem is not showing when the navigation bar's root view is presented modally

In my app I have two tabs that handle different set of functions.
One tab is the user tab, when the user switch to this tab, the tab controller checks whether the user has logged in. If not, it shows a button(LoginBtn) which triggers a log in view controller to show when tapped.
I intend to present the log in controller modally with a navigation bar.
However, the navigation bar is not showing the right button item although I've initiated it.
Here's the code
- (void)clickLoginBtn{
LogginController* _cLogginController = [[LogginController alloc] init];
UINavigationController *_cNavController = [[UINavigationController alloc] initWithRootViewController:_cLogginController];
_cNavController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"取消" style:UIBarButtonItemStylePlain target:self action:#selector(dismissLoginView)];
[_cNavController.navigationItem.rightBarButtonItem setTintColor:kColorWhite];
_cNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:_cNavController animated:YES completion:nil];
}
What could be the problem? Is it possible that is because I present to controller modally?
You have put your buttons to the login controller:
_cLogginController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"取消" style:UIBarButtonItemStylePlain target:self action:#selector(dismissLoginView)];
You shouldn't add navigation items to the navigation controller.
try this code.I think this issue is solved by this code
- (void)clickLoginBtn{
LogginController* _cLogginController = [[LogginController alloc] init];
_cLogginController .hidesBottomBarWhenPushed=No;//You need to add this line
UINavigationController *_cNavController = [[UINavigationController alloc] initWithRootViewController:_cLogginController];
_cNavController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"取消" style:UIBarButtonItemStylePlain target:self action:#selector(dismissLoginView)];
[_cNavController.navigationItem.rightBarButtonItem setTintColor:kColorWhite];
_cNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:_cNavController animated:YES completion:nil];
}
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
DemoViewController * _cLogginController = [[DemoViewController alloc]init];
_cLogginController = [storyboard instantiateViewControllerWithIdentifier:#"DemoViewController"];
_cLogginController .hidesBottomBarWhenPushed = NO;
UINavigationController *_cNavController = [[UINavigationController alloc]initWithRootViewController:_cLogginController];
_cNavController.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];
_cNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
_cLogginController.navigationItem.title = #"取消";
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:#"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(flipView:)];
flipButton.tintColor = [UIColor grayColor];
_cLogginController.navigationItem.rightBarButtonItem = flipButton;
[self presentViewController:_cNavController animated:YES completion:nil];

modalPresentationStyle from button click

I have a _exampleButton:
_exampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_exampleButton setBackgroundColor:[UIColor redColor]];
[_exampleButton addTarget:self action:#selector(certificatesButtonTouched) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_exampleButton];
and the action:
-(void)certificatesButtonTouched
{
if(!_certificatesWindow)
{
_certificatesWindow = [[AWCertificatesViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:_certificatesWindow];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
[_certificatesWindow release];
}
else {
[_certificatesWindow.view removeFromSuperview];
[_certificatesWindow release];
_certificatesWindow = nil;
}
}
this presents the window in modal view controller from other class:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancel:)];
self.navigationItem.leftBarButtonItem = cancelItem;
UITableView *table = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
[self.view addSubview:table];
_tableFromButton = table;
}
- (void)cancel:(id)sender
{
[self.presentingViewController dismissViewControllerAnimated:YES
completion:nil];
}
but after clicking the Cancel button, the Modal view controller view disappears, but if I click the _exampleButton again once- it will not appear, so I have to click it twice to show the modal view controller again. What is the problem?
It does this because that is what your code tell it to do...
You dismiss the view controller in -(void)cancel:(id)sender but this will not result in the _certificatesWindow iVar becoming nil in your first view controller. So when you touch the exampleButton again it will execute the else clause and clean up the _certificatesWindow view controller.
You should either use delegation or a code block to have the first view controller dismiss the second or remove the if/else test from your certificatesButtonTouched. Another alternative is to modify this method so that if _certificatesWindow is not nil it is reused -
-(void)certificatesButtonTouched
{
if(!_certificatesWindow)
{
_certificatesWindow = [[AWCertificatesViewController alloc] init];
}
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:_certificatesWindow];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
}
But this may or may not be desirable depending on what the second view controller shows.
I would also suggest you look at converting to ARC if possible
The problem is after you tap "Cancel", _certificatesWindow still exists when you tap on certificatesButtonTouched. It will go to the Else statement on the First tap to make _certificatesWindow = nil.
if _certificatesWindow is not needed when you tap cancel, you might want to do the following:-
- (void)cancel:(id)sender
{
[self.presentingViewController dismissViewControllerAnimated:YES
completion:nil];
[_certificatesWindow.view removeFromSuperview];
[_certificatesWindow release];
_certificatesWindow = nil;
}
allocate view like this in view did load method
if(!_certificatesWindow)
{
_certificatesWindow = [[ViewController1 alloc] init];
}
-(void)certificatesButtonTouched
{
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:_certificatesWindow];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
}
replace your code with this
-(void)certificatesButtonTouched
{
if(!_certificatesWindow)
{
_certificatesWindow = [[AWCertificatesViewController alloc] init];
}
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:_certificatesWindow];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
[_certificatesWindow release];
}

Navigation bar not changing views

I'm doing an app with a Nav bar which will switch between the first and third views (the second and the first ones will be switched by a tab bar).
In the FirstViewController.h:
#property(strong,nonatomic) ThirdViewController *thirdViewController;
In the viewDidLoad method of the FirstViewController I made it:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Model"
style:UIBarButtonItemStylePlain target:self action:#selector(goToThirdView:)];
And also...
- (void)goToThirdView:(id)sender
{
ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
self.thirdViewController = thirdViewController;
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.view removeFromSuperview];
[self.view insertSubview:self.thirdViewController.view atIndex:0];
[UIView commitAnimations];
}
My AppDelegate is looking like this:
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
But it's not working, when I click in the button, nothing happens. Any idea ?
Thank you in advance.
You should leave the selector for the button as goToThirdView:, but make that method look like this:
- (void)goToThirdView:(id)sender {
ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
[self.navigationController pushViewController:thirdViewController animated:YES];
}

UIViewController presented modally show up shifted to the top

I'm presenting a UIViewController with presentModalViewController:animated.
CMImportViewControlleriPhone *import = [[CMImportViewControlleriPhone alloc] initWithNibName:#"Import-iPhone" bundle:nil];
[import setModalPresentationStyle:UIModalPresentationFormSheet];
[import setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:import animated:YES];
[import release];
However the top bar is not visible, and it is seems shifter to the top (there is an empty space on the bottom).
This is viewDidLoad in which I set the Close button on the navigationItem
- (void)viewDidLoad
{
[super viewDidLoad];
closeButton = [[UIBarButtonItem alloc] initWithTitle:#"Close" style:UIBarButtonItemStyleBordered target:self action:#selector(closeButtonPushed:)];
[[self navigationItem] setRightBarButtonItem:closeButton];
[closeButton release];
}
thanks
You should add a navigation bar and then present modalView
CMImportViewControlleriPhone *obj = [[CMImportViewControlleriPhone alloc] initWithNibName:#"Import-iPhone" bundle:nil];
[obj setDelegate:self];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
[self presentModalViewController:navigationController animated:YES];
[obj release];
[navigationController release];
hope this helps. happy coding :)
If you're working with iPhone remove
[import setModalPresentationStyle:UIModalPresentationFormSheet];
When you add a UIBarButtonItem, the NavigationController is nil, and navigationBar is nil also. So it doesn't work with navigationItem.
closeButton = [[UIBarButtonItem alloc] initWithTitle:#"Close" style:UIBarButtonItemStyleBordered target:self action:#selector(closeButtonPushed:)];
[[self navigationItem] setRightBarButtonItem:closeButton];
You should add a NavigationController for the import object, and present it.
CMImportViewControlleriPhone *import = [[CMImportViewControlleriPhone alloc] initWithNibName:#"Import-iPhone" bundle:nil];
[import setModalPresentationStyle:UIModalPresentationFormSheet];
[import setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:import];
[self presentModalViewController:import animated:YES];
[import release];
[nc release];

changin modalPresentationStyle after rotaiting

I need help in problem. I want to change modalPresentationStyle dynamicaly when it open, after rotating event.
I write this for create modalView
ZUITableViewController *ivc = [[ZUITableViewController alloc] init];
ivc.delegate = self;
_modalIsShowing = TRUE;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:ivc];
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
nc.modalPresentationStyle = UIModalPresentationFormSheet;
}
else{
nc.modalPresentationStyle = UIModalPresentationFullScreen;
}
[self presentModalViewController:nc animated:YES];
[ivc release];
[nc release];
Scrap the if statement UIModalPresentationPageSheet behaves properly to start with.
ZUITableViewController *ivc = [[ZUITableViewController alloc] init];
ivc.delegate = self;
_modalIsShowing = TRUE;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:ivc];
nc.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:nc animated:YES];
[ivc release];
[nc release];

Resources