Storyboard UINavigation Controller Back Button Text - uinavigationcontroller

In XCode 4.5.1 creating a storyboard app with a Navigation controller, I am having a hard time trying to set the BACK button for any view controllers that are pushed. I'm using segue's and the view controller shows as expected. However I want to change the name of the navigation bar and back button dynamically and placed this in my ViewWillAppear:
self.title = #"Select Songs";
[self.backButton setTitle:#"Add"];
changes the title of the navigation bar but the back button still displays the NAME of the pushed window rather than the text "Add".
The Simulated Metrics are all Inferred. I also added a BarButtonItem to the black tray below the view in Xcode and wired up the backButton of the viewcontroller to the backButton, yet the text still does not appear.
Adding the following log messages also yield something interesting: (and yet the titlebar is updating correctly)
-(void) viewDidAppear:(BOOL)animated {
NSLog(#"%s %#", __FUNCTION__, self.navigationItem.backBarButtonItem);
NSLog(#"%s %#", __FUNCTION__, self.navigationController.navigationItem.backBarButtonItem);
}
2012-10-14 15:18:41.835 xxxx[2690:907] -[ViewController viewDidAppear:] (null)
2012-10-14 15:18:41.838 xxxx[2690:907] -[ViewController viewDidAppear:] (null)

The accepted answer is a hack, this is the way to do it...
Open StoryBoard
In Document Outline window find ViewController to which you want to
return to
Click on Navigation Item of that ViewController
In Attributes explorer change Back Button value to your custom tile
That is it, enjoy...

The back button will show the title of the previous view and if no title is set it'll show 'Back'.
So in your prepareForSegue method, you can change the title of the current view before the next view is pushed. The back button will then show whatever you set the title to.

Related

Switch back from view to tab bar view

I am trying to learn how to work with Xcode 4.5.
I have created a tab bar and would like to switch from one of the tab bar views (profile) to another view (settings -not within the tab bar menu), and back. I use below code to go to the:
- (IBAction)goToProfile:(id)sender {
ProfileViewController * profile = [[ProfileViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:profile animated:YES completion:nil];
It works fine to go to settings, but when I go back from settings view to Profile, the tab bar menu is gone. How can i go back to profile view and see the tab bar again?
I had the same problem. You can either fix it with some code or you can just make some changes in your storyboard.
If you Put a Navigation Controller between your Tab Bar Controller and the View of your selected Tab (Profile in your case). If you use a push segue to go to the next View it will take the Tabbar to the next view and also a "Back" Button. (Settings in your case)
Here's an example of my App my jubla3ForthViewController would be your ProfileViewController and one of my jubla3PDFOnlineViewControllers would be your SettingsViewController.
http://www.abload.de/image.php?img=bildschirmfoto2013-01x2kti.png
(im not allowed to post direct images because of my low reputation points)
I hope this was usefull. If it was don't forget to push the up Arrow.

How to identify the viewcontroller is clicked from More Tab or Separate tab in UITabBarController?

I have the navigationcontroller based viewcontroller and I overriding the root view controller navigation bar back button in to my custom segment control with different purpose. This navigation controller is placed one of the separate tab in the uitabbarcontroller. If this is used as the separate tab bar then no problem.
But if i use this navigationcontroller inside the more option in tabbarcontroller i am not able to come back to the more option list because of backbutton is overridden in my navigationcontroller.
My idea is add one back button only if my navigationcontroller is used more option tab otherwise i need to hidden the back button.
Please help me in this issue?
You can check if a view controller is in the 'more' section as follows:
BOOL isOnMoreNavigationController = [tabBarController.moreNavigationController.viewControllers containsObject:myViewController.navigationController];
From a UI consistency perspective it might be better to always show the back button in its standard position and move your custom buttons to some other place.

Application Crash problem on second time click on Menu Arrow of QToolButton

In my APPlication I have to show filter option (as filter option in xls)in Qtable widget for this
I have used tool Button( with property "QToolButton::MenuButtonPopup") to display Menu List and
Upon First Click upon Menu arrow it should show Menu list and selection of any of the Menu it should show only row having the text.
This functionality works fine.
But if Nothing is selected from Menu list and user has clicked Menu arrow second time then list should be hidden but in my case
application crashes giving error:
ASSERT failure in QList::operator[]: "index out of range", file ........\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qlist.h, line 447
I have written below code:
QToolButton *lToolButton = new QToolButton();
lToolButton->setPopupMode(QToolButton::MenuButtonPopup);
lToolButton->setAutoRaise(true);
lToolButton->setText("Filter");
QMenu *lMenu = new QMenu();
QAction *lAction = new QAction("All",this);
lMenu->addAction(lAction);
lToolButton->setMenu(lMenu);
Please let me know what is wrong in my coding.
Can you run your app in the debugger and find at what line in your code (not in Qt's code) the error is happening? The problem should then because more obvious.

UINavigationController custom titleView

I have a navigation controller with a root view controller for which i have the customised titleView instead of normal title for the navigation item.
If i pushed a new controller in it , the default back button title is "back", Since i have used custome titleView.
I want it to be different. I tried by setting the title in backbaritem of the root view controller, but no use.
I can create a bar button item in my pushed controller and i can set it as leftbar item, But i want it like a normal back button. [Pointing towards backward]
Is it possible to set title for the back button , if i have a custom titleView ?
Is it possible to create a bar button item as like as default back button.[Pointing towards back , other than plain,border...etc] ?
Regards,
Balaji R.
I got it.
Even though i have custom titleView for my navigation item, I can still set the title for the same navigation item where it wont be taken for the title display in navigation item . but it will taken as the title of the back button when some other controllers are pushed into it.
So , Now i'm having both title [Used for back title display] and titleView [custom view] in the navigation item.
Thanks,
Balaji R.

Substitution of detail view controller does not cause viewWillAppear to be called

I'm porting my iPhone app to iPad. On iPhone I select row in the table, and after that the next view controller is pushed to the top of navigationController (now navigation is performed on the left part of split view controller). For iPad i modified the code this way:
if (deviceIsIPad())
{
UISplitViewController *svc = (UISplitViewController *)[self findNearestParentOfClass:[UISplitViewController class]];
svc.viewControllers = [NSArray arrayWithObjects:[svc.viewControllers objectAtIndex:0],
nextViewController,
nil];
}
else
[self.navigationController pushViewController:nextViewController animated:YES];
There are no problem at iPhone code (when controller is pushed to navigation controller), but on iPad viewWillAppear: is not called (viewDidLoad is called however), while I have a reason to perform some customization right in viewWillAppear:. Why is it not called, and what should I do to force it to be called?
Much thanks in advance!
Not exactly sure what you're trying to do here but simply initializing a splitview controller and adding controllers to it does not force views to appear. You have to add the splitview controller's views to the window.
Here is the code from the Xcode Splitview template's app delegate's applicationDidFinishLaunching:
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil];
splitViewController.delegate = detailViewController;
NSLog(#"master=%#",splitViewController.viewControllers);
// Add the split view controller's view to the window and display.
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
The views in the navigation controller appear because it is already attached to the window and displaying the view of one of its controlled controllers.
Edit:
From Comments:
All initialization code you are quoted
here is already performed. Now, let's
assume one have a table on the left
controller, then he select another row
there, and want to replace right
controller with another one.
splitViewController.view is added on
the window фдкуфвн, because some GUI
elements initialized in viewDidLoad,
are properly presented on view
It sounds like your problem arises because the detail (right-side) view of a splitview controller is always visible i.e. it only appears i.e calls viewWillAppear, once immediately after first being loaded. There is no point at which the detail side has no view present. I'm not sure what entirely swapping out viewControllers of the splitview will do.
If you want to change the detail view on the fly. You need to put a navigation controller in the right side and then push and pop view-controllers in that nav in response to events in the right side controller.
Look at how the iPad iPod app works. You have a leftside view of playlist and on the right side, a list of all the songs in the playlist. Selecting a song pushes a song detail view on top the list of songs.

Resources