UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:self action:#selector(pop)];
self.navigationItem.backBarButtonItem = barBtnItem;
I placed the above code in iphone it is working.when i am trying it for ipad it is not working.what may be reason?
Thanks in Advance
This changes NavigationBar's BackButton text, to do before pushing a new view controller :
UIViewController *myViewController = [[UIViewController alloc] init];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"My text" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[self.navigationController pushViewController:myViewController animated:YES];
And it works for both iPhone and iPad devices.
It looks like you linked your UINavigationController with Interface Builder, you should have a look at this :
Related
I'm trying to add Previous/Next buttons above the keyboard like in mobile Safari. There are a lot of questions about that here on StackOverflow, but most answers are to use inputAccessoryView.
I tried that and it looks like this:
Is there anyway to have the buttons in the toolbar bellow, like it works in mobile Safari??
This is how it looks like in Safari:
It seems what I was looking for is inputAssistantItem.
It allows you to add and change buttons in the keyboard's shortcut bar.
UIBarButtonItem* nextButton = [[UIBarButtonItem alloc]
initWithImage:nextImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(nextField:)];
UIBarButtonItem* previousButton = [[UIBarButtonItem alloc]
initWithImage:previousImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(previousField:)];
NSArray *buttonGroups = #[[[UIBarButtonItemGroup alloc]
initWithBarButtonItems:#[previousButton, nextButton]
representativeItem:nil]];
textField.inputAssistantItem.trailingBarButtonGroups = buttonGroups;
UIBarButtonItem *previous = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:103 target:self action:#selector(previousButtonTapped:)];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixedSpace setWidth:6.0];
UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:104 target:self action:#selector(nextButtonTapped:)];
I have a viewController A, is it possible that I pre-set the back button of viewController B when it is pushed to.
Controller *B = [Controller viewControllerFromStoryboardWithProfile: profile editMode: NO];
UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:#"Home"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[B.navigationItem setBackBarButtonItem:newBackButton];
[self.navigationController pushViewController:B animated:YES];
Something like this?
Try this code:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Home"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[self.navigationController pushViewController:anotherViewController];
source: How to create backBarButtomItem with custom view for a UINavigationController
Why would my UIBarButtonItem sometimes disappear?
When you first load the screen (the first in a Tab Bar) it displays fine. However when you navigate to a new screen and then return both left and right buttons disappear. They aren't reacting to touch events either. However, if you go to a second tab and return they suddenly appear.
It must be a recent iOS change 'cos it was working previously.
==== UPDATE
The code is hardly rocket science but here it is:
Screen 1:
In viewDidLoad:
UIImage *myImage = [UIImage imageNamed:#"image.png"];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:myImage
style:UIBarButtonItemStyleBordered
target:self
action:#selector(myAction:)];
self.navigationItem.rightBarButtonItem = item;
and
- (IBAction)myAction:(id) sender {
MyController *mc = [[MyController alloc] initWithNibName:#"MyController" bundle:nil];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Title" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
I set the buttons of my NavigationBar this way:
UIBarButtonItem *addAcc = [[UIBarButtonItem alloc]
initWithTitle:#"Add"
style:UIBarButtonItemStylePlain
target:self
action:#selector(addNewAcc)];
UIBarButtonItem *delAcc = [[UIBarButtonItem alloc]
initWithTitle:#"Del"
style:UIBarButtonItemStylePlain
target:self
action:#selector(DeleteButtonAction)];
NSArray *arrBtns = [[NSArray alloc]initWithObjects:addAcc,delAcc, nil];
self.navigationItem.rightBarButtonItems = arrBtns;
This works well but after rotating the device or changing the buttons, they get much longer.
How can I solve this?
Regards
Here is a screenshot:
Before rotating : http://i.stack.imgur.com/9W3Hl.jpg
After rotating : http://i.stack.imgur.com/M27Hx.jpg
you should play with the property autoresizngmask of the buttons,
and autoriszessubViews .
check the refference :
autorizing
I am trying to show a custom tableview inside a popover view in my iPad App. This is working fine. I wanted to add buttons on toolbar (at the bottom of tableview). Toolbar is shown empty. Any suggestion?
Note that following code is triggered when user touches the button in main view controller.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.customTableViewController];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:#"item 1" style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:#"item 2" style:UIBarButtonItemStylePlain target:nil action:nil];
[navigationController setToolbarHidden:NO];
navigationController.navigationBar.topItem.title = #"Some Title";
NSArray *array = [[NSArray alloc] initWithObjects:item1, item2, nil];
[navigationController setToolbarItems:array];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
self.popoverController = popover;
popoverController.delegate = self;
[popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I'm hitting a similar issue, the tableview shows fine in the popover, but the buttons below are not visible. I'll let you know if I figure something out.
EDIT: My issue was that I was re-sizing the popover, and the buttons were being pushed out of the view. I fixed this by changing the autosizing to lock the position relative to the bottom of the frame. To do this, look at your xib in interface builder, go to the Ruler tab on the upper right and use the Autosizing GUI. For mine this meant that only the bottom anchor was selected on the GUI.
On ipad apps, you've got to set toolbar items to the "topViewController" (yes this is counter-intuitive).
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:catView];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:#"item 1" style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:#"item 2" style:UIBarButtonItemStylePlain target:nil action:nil];
[nav setToolbarHidden:NO animated:YES];
// WRONG: [nav setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];
// CORRECT (for ipad apps):
[nav.topViewController setToolbarItems:[NSArray arrayWithObjects:item1, item2, nil] animated:NO];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:nav];
See:
http://www.kevatron.co.uk/tag/uipopovercontroller/