Navigation bar is missing while pushing kalviewcontroller on button click.How to add navigation bar? so that it can be pop to view controller where its being pushed on button click.
kal = [[[KalViewController alloc] init]autorelease];
kal.title = #"Calendar of game";
kal.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
action:#selector(addEvent)] autorelease];
kal.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStyleBordered target:self action:#selector(backToPrevious)]
autorelease];
kal.delegate = self;
dataSource = [self init];
kal.dataSource = dataSource;
[self.navigationController pushViewController:kal animated:YES];
Put [self.navigationController setNavigationBarHidden:FALSE] in you viewDidLoad(assuming you have created navigation controller).
Related
I want to add method that opens up the new view controller when this info button is pressed.
UIBarButtonItem *infoItem = [[UIBarButtonItem alloc]
initWithTitle:#"Info"
style:UIBarButtonItemStyleBordered
target:nil
action:#selector(action)];
-(void)action {
MyViewController *myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[myView presentModalViewController:YES]; // present view modally
[self.navigationController pushViewController:myView animated:YES]; // add to navigation stack
[myView release];
}
I can't make my UIBarButtonItem to display. I simplified it as much as I could, but even this does not display the bar :
- (void)viewDidLoad {
UIBarButtonItem *supprBouton =[[UIBarButtonItem alloc]
initWithTitle:#"Supprimer"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(supprimerDate:)];
self.navigationItem.rightBarButtonItem = supprBouton;
UIBarButtonItem *enregBouton = [[UIBarButtonItem alloc]
initWithTitle:#"Enregistrer"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(enregFichier:)];
self.navigationItem.leftBarButtonItem = enregBouton;
[enregBouton release];
[supprBouton release];
}
One right button, one left, this should be displayed at least, no ? What can be wrong ?
Without more context, my best guess is that you have not yet set up a UINavigationController.
Try to add a uinavigationcontroller to your view:
UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navCntrl1 = [[UINavigationController alloc] initWithRootViewController:vc];
I have added a new file to my project in that i am creating the screens programatically and i used following code to create a grouped table view with a title bar & 2 buttons on title bar, but its creating only grouped table but not title bar y it is so, can any one help me thanx in advance
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Add Item";
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:#selector(cancel_Clicked:)] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:#selector(save_Clicked:)] autorelease];
self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 415)style:UITableViewStyleGrouped];
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
}
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithTitle:#"+"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(Add)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
[journeylist.tabBarItem initWithTitle:#"Journey List" image:[UIImage imageNamed:#"listIcon-H.png"] tag:1];
journeylist.navigationItem.title =#"Journey List";
NSArray *controllers = [NSArray arrayWithObjects:journeylist,appstore,settings,about,nil];
self.viewControllers = controllers;
Try this.
Your table frame is CGRectMake(0, 0, 320, 415) so top left, you'll need to leave room for the title bar say CGRectMake(0, 40, 320, 415).
I think you have to present it like this.
SomeViewController *controller = [[SomeViewController alloc]
initWithNibName:#"SomeViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:controller];
navController.navigationBar.tintColor = [UIColor grayColor];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[controller release];
Edit
When you are showing that controller with table view you have to frist add it to a navigation controller in order to show the navigation bar.
I see that a similar question was asked here: How to add a right button to a UINavigationController? (among others) but its not quite what I'm looking to do and they arent solving my problem.
Essentially, I've created a UIViewController called WebViewViewController with a UIWebView on it which will be shown using presentModalViewController. Essentially its a mini web browser to display a web page while keeping the user in the app rather than launching Safari.
The viewController does the following to get it to show... and the "done" button is meant to provide a place to close the browser.
-(IBAction)visitFacebook {
WebViewViewController *rootController = [[WebViewViewController alloc] init];
rootController.webURL = #"http://www.facebook.com/";
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(done:)];
[navigationController.navigationItem setRightBarButtonItem:doneButton animated:YES];
[navigationController.navigationItem setTitle:#"Facebook"];
if (rootController) {
[self presentModalViewController:navigationController animated:YES];
}
[doneButton release];
[rootController release];
}
Unfortunately the "done" button isnt showing.. any ideas where im going wrong?
Try with below
-(IBAction)visitFacebook{
WebViewViewController *rootController = [[WebViewViewController alloc] init];
rootController.webURL = #"http://www.facebook.com/";
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(done:)];
rootController.navigationItem.rightBarButtonItem = anotherButton;
[navigationController.navigationItem setTitle:#"Facebook"];
if (rootController) {
[self presentModalViewController:navigationController animated:YES];
}
[doneButton release];
[rootController release];
}
Perhaps you're looking for something more like this:
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStyleDone target:self
action:#selector(dismissModalViewControllerAnimated:)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStylePlain target:self action:#selector(done:)];
Just this one line code displayed done button for me.
Here in my application i created a leftbarbuttonitem programatically in viewWillAppear methos, i have two click twice to work this, my code is as follows.
Code for creating UIBarButtonItem(left bar button)
goingBackButton = [[UIBarButtonItem alloc] init];
goingBackButton.title = #"Back";
goingBackButton.target = self;
goingBackButton.action = #selector(backAction);
self.navigationItem.leftBarButtonItem = goingBackButton;
[goingBackButton release];
Action code
- (IBAction) backAction {
NSLog(#"Inside the backAction of uploadViewController");
[self.navigationController popViewControllerAnimated:YES];
NSLog(#"Inside the backAction1 of uploadViewController");
}
Try the below code:
UIBarButtonItem *bar = [[UIBarButtonItem alloc]initWithTitle:#"back" style:UIBarButtonItemStyleDone target:nil action:#selector(back)];
self.navigationItem.leftBarButtonItem = bar;
[bar release];
-(void)back
{
[self.navigationController popViewControllerAnimated:YES];
}