I've created a project with Navigation-based Application template, and did some work and ran it.
I expected if I touch a cell, new view will show up and new icon (which is going back button) will show up on navigation-bar item too.
But for some reason, the 'back button' is not added automatically. What can be the problem??
Below is my code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
MessageView *detailViewController = [[MessageView alloc] initWithNibName:#"MessageView" bundle:nil];
NSDictionary* aMessage = [m_tableData objectAtIndex:indexPath.row];
detailViewController.m_message = [[NSDictionary alloc] initWithDictionary:aMessage];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
You probably haven't given your parent controller a title (just self.title = #"my name" in viewDidLoad or viewWillAppear). That's what gets filled in by default in the back button, so if you don't name it, you don't get a back button.
You are saying that MessageView is inherited from UIView. But I think if there's no problem to push into the navigation controller then it would be UIViewController's subclass.
There are some reasons for not displaying back button:-
1.) As Mackworth told that you have not given any title from which you are navigating.
2.) your Navigation Bar's back button property is set for hidden.
Otherwise back button should be appear on the navigation bar.
It seems you haven't set your Navigation Bar Title in the View from where you are navigating...
Once you set the title of navigationbar by default it will show you the back button
Use it in either ViewDidLoad or ViewWillAppear.
self.navigationItem.title=#"Set Your Title here";
Related
I would like my navigation controller to act the way that ios7 does = display the previous view title.
It doesn't always work for me
I have a SettingViewController :
- (void)viewDidLoad
{
self.navigationItem.title = NSLocalizedStringFromTableInBundle(#"account_settings", nil,[GeneralUtil getLangBundle],nil);
self.navigationController.navigationBar.translucent = NO;
[super viewDidLoad];
}
When clicking on a button it opens the Profile Picture view controller like this:
UIViewController *vc = [[UIStoryboard profilePictureStoryBoard]instantiateInitialViewController];
[self.navigationController pushViewController:vc animated:YES];
The profile picture is opened successfully but the title of the back button is Back and not the title of the Settings View controller which is Settings.
What could be the problem?
The back button changes its text in iOS 7 depending on the length of the title it needs to display.
If the name of the previous viewcontroller is too long to fit, it will instead just say 'Back'. If there's not even enough room for 'Back', it will just show the arrow.
I have a MenuViewController and a UINavigationController sitting inside a ViewDeck, a framework for a side menu. You simply initiate like so:
ListingViewController* lvc = [[ListingViewController alloc] init];
UINavigationController* homeNavStack = [[UINavigationController alloc] initWithRootViewController:lvc];
MenuViewController* sideMenu = [[MenuViewController alloc] init];
IIViewDeckController* slideController = [[IIViewDeckController alloc] initWithCenterViewController:homeNavStack leftViewController:sideMenu];
Where the center view controller is my navigation controller, and the menu view controller is hidden on the left, and you must slide to the left to make it visible (similar to facebook's side menu).
There is a button in the side menu, that when pressed, needs to transition the app back to the navigation controller, and have it push a new view controller. Here is my code for this, inside MenuViewController.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 0){
NSLog(#"check");
UserProfileViewController* userProfile = [[UserProfileViewController alloc] init];
[self.viewDeckController toggleLeftViewAnimated:YES];
[self.centerViewController pushViewController:userProfile animated:YES];
}
}
toggleLeftViewAnimated brings back the center view controller, hiding the side menu again. I have given the side menu a reference to the center view controller, and using this, I ask it to push a new view controller. However when this method is called, nothing happens after the center view controller comes back into view. Does anyone know why this won't work?
Check whether the self.centerViewController is a Navigation Controller instance that you have added as center view controller. You need to get the instance of Navigation Controller you have added in to the IIViewDeckController where now you are using self (which might be the MenuViewController). I think you need to write a method to get the navigation controller form the IIViewDeckController and after that pushing your userProfile will work perfectly.
I have a navigation view controller which navigates between some tableviews and I've just added an "edit" button inside the cells of one of the tables. What I'd like to happen is for the user to tap the edit button inside the cell and for the navigation controller to shunt across a new view where all of that cell's content is laid out for easy editing.
The cell, however, has no access to the navigation controller and cannot push a new view controller on to its stack. How can I do what I want?
Note that I am not using segues and storyboards as it's an old app and I want to continue supporting devices running iOS 4.
You should set the target of the button to the UIViewController that is already on the stack?
If you don't want to add this new view to the Navigation (Stack), Simply use the PresentModalViewController
// In action method for edit button
- (void)editButtonClicked {
EditViewController *editViewController = [[EditViewController alloc] initWithNibName:#"EditViewController" bundle:nil];
[self.navigationController presentModalViewController:editViewController animated:YES];
[editViewController release];
}
I'm not sure if you want this, but you can try:
// In action method for edit button
- (void)editButtonClicked {
EditViewController *editViewController = [[EditViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:editViewController animated:YES];
[editViewController release];
}
I'm changing the back button item title in the viewDidAppear of a controller in the following way:
self.navigationController.navigationBar.backItem.title = #"Previous";
It changes the tittle properly, but the I'm having a strange behaviour. When I select the "previous" button, it changes the tittle of the controller that is up in the stack (i.e the parent controller now has the title "Previous".
Do you now why this happened?
When you're using a navigation controller, calling [self setTitle:#"Title"]; inside of any view controller in the stack will set the navigation bar title. This is also the title used by default for the back button when you've pushed a new view controller. Apparently, from what you are experiencing, explicitly setting the title of the backItem, also sets it for the navigation bar title for the previous view controller overriding whatever what specified in the call to -setTitle in the view controller.
You will probably be better off just managing the title from within the view controllers in your navigation stack. When you go to push a new view controller, do this:
[self setTitle:#"Previous"];
NextViewController *controller = [[NextViewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
Now, when the next view controller displays, the back button with say "Previous". Now, you just need to change it back to whatever its real title should be in -viewWillAppear:
- (void)viewWillAppear:(BOOL)animated;
{
[self setTitle:#"Real Title"];
[super viewWillAppear:animated];
}
It may feel a little hacky, but it's better than trying to override the navigation bar functionality. Wrestling with the nav bar/nav controller stack can prove very frustrating.
Best regards.
I am having a problem with a table and showing another view when the user touches a table cell. I am using a UITabBarController for the main view to show different views. I then use a UINavigationController when the user selects a UITableView view to display the next view from the table cell selection.
My problem is this: when they select the table cell, the cell is highlighted and the next view does not appear. I am using IB. All of the examples I have found are doing this the same way I am, except the examples work!
I have the controllers loaded in a NSMutableArray with a Dictionary. I also tried this code by directly creating a view controller rather than using the array item. Same results....
I checked the target controller (Calc1ViewController) to make sure there was nothing wrong with the controller. When showing it directly, the controller (Calc1ViewController) displays correctly.
Here is some code.....
The initialization of the view controller in the dictionary:
Calc1ViewController *calc1ViewController = [[Calc1ViewController alloc] init];
[menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(#"SSC - page 1",#""), #"title",
calc1ViewController, #"viewController",
nil]];
[calc1ViewController release];
I also tried this without using the dictionary -- creating a view controller in place of the [[menuList objectAtIndex:...]; line -- by creating the view controller like this:
Calc1ViewController *targetViewController = [[Calc1ViewController alloc] init];
// the table's selection has changed, switch to that item's UIViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *targetViewController = [[menuList objectAtIndex: indexPath.row] objectForKey:#"viewController"];
[[self navigationController] pushViewController:targetViewController animated:YES];
targetViewController = nil;
}
The navigation controller is defined in the AppDelegate and connected to the RootViewController through IB.
When I select a table row, it shows in the debugger that the pushViewController code is executed, but the next view does not show. Here is an example:
alt text http://thecoolestcompany.com/ssc-table-view.jpg
Any ideas?
Finally figured it out......
I had the UINavigationController and the UITabBarController on the same level. After moving the Navigation Controller as a child to the tab bar controller, everything worked. You may add as many navigation controllers to a tab bar as you would like. In IB is is a little confusing. You need to drag the NavigationController into the TabBar to as it as a new Tab Bar item.
Theres not much to go by with t he code you have provided. Only thing i can think of without looking at more code is that perhaps you have not initialized your view controller (the one in your dictionary) correctly, or at all, or the dictionary you are accesing there is not the correct one...
What is the value of [self navigationController] when pushViewController is called. Is it nil?
What is the value of targetViewController when it is passed to pushViewController. Is it nil?