please help me with this
this is really erratic I am unable to add a button to navigation bar of modalview
UINavigationController *tempModalVC=[[UINavigationController alloc] init];
[tempModalVC.navigationBar setBarStyle:UIBarStyleBlack];
//UIBarButtonItem *tempDoneBTN=[[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:#selector(hideModalView:)];
UIBarButtonItem *tempDoneBTN=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(hideModalView:)];
[tempModalVC.navigationItem setBackBarButtonItem:tempDoneBTN];
[tempModalVC.navigationItem setTitle:#"Title"];
tempModalVC.navigationItem.backBarButtonItem.enabled=YES ;
//[tempModalVC.navigationBar setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStyleBordered target:self action:#selector(hideModalView:)]];
//[tempModalVC.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStyleBordered target:self action:#selector(hideModalView:)]];
[tempDoneBTN release];
[tempModalVC.view addSubview:mapView];
tempModalVC.modalPresentationStyle = UIModalPresentationFormSheet;
Please help me with this I have tried almost every permutation combination.
Thnx in advance
It looks as if you want to display a mapView in a modal view.
On iPhone, modal views occupy the entire screen, so there is no room for a nav bar. Thus you do not need a navigation controller.
I assume the above code is inside a UIViewController instance. If so, just do this:
[self presentModalViewController:mapView animated:YES/NO];
In this case, in your your mapView controller, you should add a button that, when pressed does this:
[self dismissModalViewControllerAnimated:YES/NO];
Related
I am in great trouble....How can i set next and previous button/arrow at my segmented bar...if anyone need brief about my problem then please see this link...How can i add a next and previous button at the segmented Controller?
i have attached an image to understand the problem...so anybody help me please....
NOTE THAT: In my current project it has more than 5 buttons to add at the segmented bar so when i will press next/previous arrow then segmented bar should be move from his place.If my question is not clear to you then please see my another link....
Thanks in Advance
EDIT:
UIBarButtonItem *previousBarButtonItem = [[UIBarButtonItem alloc] //init];
initWithTitle:#"<"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(previousBarButtonAction:)];
self.navigationItem.leftBarButtonItem = previousBarButtonItem;
[previousBarButtonItem release];
UIBarButtonItem *nextBarButtonItem = [[UIBarButtonItem alloc] //init];
initWithTitle:#">"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(nextBarButtonAction:)];
self.navigationItem.rightBarButtonItem = nextBarButtonItem;
[nextBarButtonItem release];
//This Portion For UIToolbar
topToolBar = [UIToolbar new];
topToolBar.barStyle = UIBarStyleDefault;
[topToolBar sizeToFit];
topToolBar.frame = CGRectMake(50, 410, 280, 50);
//Add buttons
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:#selector(pressButton1:)];
UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:#selector(pressButton2:)];
UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self action:#selector(pressButton3:)];
//Use this to put space in between your toolbox buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
//Add buttons to the array
NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil];
//release buttons
[systemItem1 release];
[systemItem2 release];
[systemItem3 release];
[flexItem release];
//add array of buttons to toolbar
[topToolBar setItems:items animated:NO];
self.navigationItem.titleView = topToolBar;
this is my current coding position now i have 4 buttons in the uitoolbar but only 3 button can see so i want to move this toolbar when i will press next or previous button to see the others button whose are out of frame of uitoolbar??
EDIT:
I able to scroll the navigation bar item using uiview animation but now my problem is when i press the next/prev button then it is moving from the current place according to the changing of the coordinate of the uitoolbar and moving over the pre/next baritem frame whose are not in the uitoolbar items. but it should be wothin a uiview and should change the coordinate within the uiview not out of the view...now tell me what can i do for this problem.
Firstly in figure the NavigationBar you are seeing is actually UIToolBar. Unfortunately it is not possible to add anymore controls on the UINavigationBar. But you can achieve exactly same UI with UIToolBar where you can add any controls.
So to achieve this use UIToolBar and not UINavigationBar. Also use UIBarButtonItem with custom title to achieve Next and Previous functionality.
EDIT
Here are few links for example of UIToolBar
http://www.codeproject.com/Articles/43658/How-to-Make-a-Toolbar-with-UIToolbar
http://osmorphis.blogspot.com/2009/05/multiple-buttons-on-navigation-bar.html
http://atastypixel.com/blog/making-uitoolbar-and-uinavigationbars-background-totally-transparent/
But this all explains using codes. Instead using Interface Builder, it becomes too easy to use UIToolBar (if coding is not so important).
I think this is being slightly overcomplicated- can you not just set the text of the two UIBarButtonItems to "<" and ">"?
I'm looking at some other iPad apps that have the capability to add extra icons into the leftBarButtonItem and rightBarButtonItem for UINavigationController. Here is a picture of one taken from nngroup.com:
In order to do something like this, are they subclassing UINavigationController or adding a category for it? Or are they doing something different? I kind of just wanted the general approach of how to do something like this, but don't need all the code since I'm sure it's a lot of work. Thanks.
You can create a toolbar object and add the buttons to that toolbar and then set the custom view of the right bar button item or left bar button item as this toolbar.
A sample implementation is like this.
UIToolbar * toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0,0,160, 44.5)];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];
UIBarButtonItem * deleteButton = [[UIBarButtonItem alloc]
initWithTitle:#"Delete"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(deletePressed)];
// Button style is the default style
[buttons addObject:deleteButton];
[deleteButton release];
UIBarButtonItem * barItem = [[UIBarButtonItem alloc] initWithTitle:#"Logout" style:UIBarButtonItemStyleBordered
target:[Y3AppDelegate mainApplicationInstance] action:#selector(logout)];
[buttons addObject:barItem];
[barItem release];
// put the buttons in the toolbar and release them
[toolbar setItems:buttons animated:YES];
[buttons release];
// place the toolbar into the navigation bar as Right Button item
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithCustomView:toolbar] autorelease];
[toolbar release];
One thing to note here is that you may have to change the tint color of the toolbar to match with that of the navigation bar. Hope this answer helps you.
You can hide Navigation bar and instead of that show an image of navigation bar and then place buttons on it :))
I have a UIButton that pushes to another view controller using the following code. How do I go about putting this UIButton to the top bar of a navigation controller.
-(IBAction) nextButtonPressed {
TipsViewController *objYourViewController = [[TipsViewController alloc] initWithNibName:#"TipsViewController" bundle:nil];
[self.navigationController pushViewController:objYourViewController animated:YES];
[TipsViewController release];
}
I was thinking of adding something like: self.navigationItem.rightBarButtonItem somewhere, but can't figure out the syntax.
Here's something else I tried with the following code: I can get a "Next" button in the top bar of the Navigation Controller. How would I get it to push to another view controller?
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Next" style:UIBarButtonItemStylePlain target:self pushViewController:anotherButton animated:YES];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
thanks for any help.
When you init your UIBarButtonItem, do you see a parameter called action: ? Mention a selector there:
UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:#"Next" style:UIBarButtonItemStyleBordered target:self action:#selector(Next:)];
The above item should be your rightBarButton as you want it to be.
And this would be your selector:
-(void)Next:(id)sender {
[self.navigationController pushViewController:nextViewController animated:YES];
}
UIBarButtonItem addButton=[[UIBarButtonItem alloc]initWithTitle:#"+" style:UIBarButtonItemStyleBordered target:self action:#selector(method)];
I have a UITableViewController A that is pushing UITableViewController B onto the stack.
In A i have the code:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Trending"
style:UIBarButtonItemStylePlain
target:self
action:#selector(backButtonClicked:)];
backButtonClicked: is also implemented.
B has the title Trending, but when I click it, it doesn't ever reach backButtonClicked:
Why is this?
Try either setting the delegate:
[navigationController setDelegate:self];
Or using the left button. Sometimes the back button doesn't work with certain views and I have had to use the left button instead:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Trending" style:UIBarButtonItemStylePlain target:self action:#selector(backButtonClicked:)];
Also, you can try setting B's button item instead of A:
viewControllerB.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Trending" style:UIBarButtonItemStylePlain target:self action:#selector(backButtonClicked:)];
In the Xcode documentation, it states that the backBarButtonItem target and action should be set to nil. So even if you do set it, it's probably a good bet that it will be ignored. You could check out the link below to add custom behaviour to the back button.
Custom Action on Back Button Item
Or you could just do the following in viewControllerB:
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Trending"
style:UIBarButtonItemStylePlain
target:self
action:#selector(backButtonClicked:)] autorelease];
Then also add this to viewControllerB
- (void)backButtonClicked:(id)sender {
[[[self.navigationController viewControllers] objectAtIndex:0] backButtonClicked:sender];
[self.navigationController popViewControllerAnimated:YES];
}
The above method will find the RootViewController and send it the backButtonClicked message. It will then pop the current view controller, which should allow you to emulate the backBarButtonItem. Also you can change which view controller you want to send the message by changing the value in the objectAtIndex method.
try not backBarButtonItem but leftBarButtonItem instead
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Trending" style:UIBarButtonItemStylePlain target:self action:#selector(backButtonClicked:)];
self.navigationItem.hidesBackButton=YES;
for me it works like a charm. And don't forget that you didn't release this button - and it can cause memory leak. So you can add autorelease when you assign you button or make it like this
UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithTitle:#"Trending" style:UIBarButtonItemStylePlain target:self action:#selector(backButtonClicked:)];
self.navigationItem.leftBarButtonItem = myBackButton;
[myBackButton release];
self.navigationItem.hidesBackButton=YES;
how can i display a image on button which is presented on UINavigationController iphone ?
if you mean the back button that is displaying on the Navigation Bar
you can do
UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithTitle:#"title" style:UIBarButtonItemStyleBordered target:nil action:nil];
barBtnItem.image = [UIImage imageNamed:#"image.png"];
self.navigationItem.backBarButtonItem=barBtnItem;
[barBtnItem release];
Put this code in the Previous page's viewDidLoad method or anywhere else before
[self.navigationController pushViewController:viewController animated:YES];
this line