I am trying to add the "Back button" to a couple of my view to a specific view that come before them.
View A has 2 buttons, to view B and C, I want B and C (And all following views) to have the "back button", but I don't want it to appear once I'm in view A.
In this example, I'll only show what I've done with view A and B.
I added the navigation controller between A and B, and as you can see, "Shows Navigation Bar" is ticked on. The segue between A and B is "present modally".
For some reason it doesn't show in my storyboard, but view A is a tabbed view connected to a tabbarController. What am I doing wrong ?
Your root view controller (first one, basically) needs to be a UINavigationController in order to have that navigation bar and back button work natively.
Also, presenting a UIViewController modally does not show a navigation bar (and subsequently the back button). Only when you push a UIViewController onto the navigation stack will the navigation bar and back button show.
Here is an example of pushing a view controller from another view controller that is within a UINavigationController:
func buttonPressed() {
let nextViewController = UIViewController()
self.navigationController?.pushViewController(nextViewController, animated: true)
// As long as your navigation bar is not set to hidden,
// doing this will push nextViewController onto the navigation stack
// and show the back button + navigation bar.
}
Related
I'm quite new in swift programming but couldn't find an answer to the question how to change the title of the navigation bar when the user taps on it (see example app "ToDo" from Microsoft [former Wunderlist]). So first I choose the "Item A" out of a tableview and in the following screen the title stands in the navigation bar - so far so good. With a tap on this title "Item A" it should be possible to change the title (also for the previous tableview with the list of items by saving the changes in Realm). For now I just use the commands
title = selectedItem!.title
in my viewDidLoad in the upcoming view controller where .title equals the title from my "Item"-class
class Item: Object {
var parentCatergory = LinkingObjects(fromType: Category.self, property: "items")
#objc dynamic var title: String = ""
}
Any ideas? Or do I have to use a customized navigation bar, if so how?
Thanks in advance!
According to the UIViewController lifecycle, anything that you add to the method viewDidLoad() will be executed once when the view is loaded. If you want to change the title property on demand on a ViewController, is necessary invoke the navigation bar title property again from your tab action method. Check this post for more information: How to set the title of a Navigation Bar programmatically?
Goal: window close button to be present at all times..
I tried to use
override func viewDidAppear() {
var button = view.window?.standardWindowButton(NSWindowButton.CloseButton)
button?.enabled = true
}
But when i move from one view controller to the other, the close window button is still disabled. Note that the view controllers are presented as sheets..
How can i have the button enabled in all view controllers?
I have a split view controller with master view being something like a menu allowing users to pick the scene for detail view (I have multiple detail views). On one of the detailView scene, I have a button that presents a view controller modally and "Over Current Context" as it has a translucent background and I wanted to create that fog effect. This particular detailView (lets call it TodayViewController) is also the initial detail view controller when the app loads, and only changes when user selects a new view controller from the master view (menu).
This is what I meant in code:
When app just starts:
splitViewController.viewControllers[1] // returns TodayViewController
When user selects from the menu:
splitViewController.viewControllers[1] // returns a different view controller
So the issue I am having is that when the app just starts (bullet 1), when I present a child view controller of TodayViewController modally and "over current context", the child VC presents itself over both the master view (menu) as well as the detail view (TodayViewController), causing the entire screen to have a foggy effect. This is the effect that I want
However when I select another view controller (from the menu) and then select back TodayViewController and try to present the child VC it only presents itself over the detail view now. Meaning that the foggy effect is only present on the detail view and the master view (the menu again) remains clear. How do I fix this?
I hope I'm clear enough with my explanation. Here are some of my code:
My GlobalSplitViewController.swift:
import UIKit
class GlobalSplitViewController: UISplitViewController, UISplitViewControllerDelegate {
func primaryViewControllerForCollapsingSplitViewController(splitViewController: UISplitViewController) -> UIViewController? {
let detailViewController = self.viewControllers[1] as! TodayViewController
return detailViewController
}
func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
return true
}
func splitViewController(svc: UISplitViewController, shouldHideViewController vc: UIViewController, inOrientation orientation: UIInterfaceOrientation) -> Bool {
return false
}
}
GlobalSplitViewController is structured so that TodayViewController is presented first on iPhones, but on iPad it shows both master and detail view, uncollapsed.
'Over current context' is supposed to present over only the master or the detail wherever it is called from. I'm not sure why it doesn't work properly at first (but I understand that's what you want) but then works when you select another option. Anyhow, to achieve what you want, stop using 'over current context'. That will present the fog vc over the whole screen.
I have an initial view controller. It goes to the next view controller which has the “picker wheel” in it. From that screen, if the user selects one of the 4 items in the picker wheel and stops on it. Then press ONE action button to initiate several C code statements.
I need specific help with coding the statement (s) that cause the transition from one view controller to another view controller.
I’m thinking out loud, it should look something like this (but I really don’t know):
‘If row = 0 then go to View controller B.’
‘If row = 1 then go to View controller C’
etc.
Or use some other ‘VERY SIMPLE’ method for transitioning from a ‘selection from a picker wheel to another view controller’.
Basic documentation.
I have 4 viewcontrollers :
First view controller is named - VCa
Second view controller is named - VC1
Third View controller is named - VCb
Forth view controller is named - Vcc
There is nothing but the default 'Storyboard" coding in this VCa (view controller).
The first view controller only has a label named VCa , so we can see which VC this is.
And it has a button named Button A, so I can do a modal segue to the next view controller named VC1.
The second view controller (VC1) only has some basic things.
The picker wheel named pickerView1. The array named Companies with data.
A button to go back to the first view controller VCa.
The button is named B1Back.
A button to go forward to the next view controller named VCb.
The pupose for this button is only for demo. purposes to transition to VCb.
It has nothing to do with coding a solution to allow the picker wheel selection to . transition somehow to the next view controller.
The button is named B1forwardtob.
The same is true for the 3rd button. It just allows this VC (VCa) to transition to . . another view controller named VCc. The button is named B1forwardtoc.
An ACTION button that does nothing, yet. I’m hoping the transition from view controller to view controller code goes here (after the action button). But again I don’t know what I don’t know.
There is nothing but the default 'Storyboard" coding in this VCb (view controller).
The third viewcontroller (VCb) is very simple too. It is there just to go to and then go back to VC1.
There is nothing but the default 'Storyboard" coding in this VCc (view controller).
Same for the forth viewcontroller (VCc). It is there just to go to and then go backto VC1.
It's sort of hard to tell what you're asking, but are you looking for something like this?
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
UIViewController *viewControllerToDisplay;
if (row == 0) {
viewControllerToDisplay = [[ViewControllerB alloc] init];
} else if (row == 1) {
viewControllerToDisplay = [[ViewControllerC alloc] init];
}
if (viewControllerToDisplay) {
[self presentViewController:viewControllerToDisplay animated:YES completion:nil];
}
}
Sencha adds a nice Back button to the navigation bar. As shown below.
So my questions are:-
How can I dynamically add the Next button to the navigation bar?
How do I style the Next button to have a triangular edge, similar to what the Back button has?
You can change appearance of button to look alike forward button by setting ui : "forward" config for button.
You can add buttons to navigation bar with following way -
navigationBar : {
items:[
{
xtype:'button',
text:'Forward',
ui:'forward'
}
]
},
You can also add buttons dynamically to navigation bar from controller. First get instance of navigation view and then navigation bar. Create some buttons and add them to it.
var navBar = this.getMyNavView().getNavigationBar();
var button = Ext.create('Ext.Button', {
text: 'Button'
});
navBar.add(button);
update
Found this issue for ui : 'forward' on sencha forum. Have a look at it.
http://www.sencha.com/forum/showthread.php?253899-When-using-ui-forward-and-back-the-buttons-are-not-being-rendered-properly