I just now figured out how to add a new view when you press a button. For example, in my storyboard, I am using a tabbed controller and in my first viewController i have a button in the top right corner on a navigation bar. and when i press that button, it directs to another view controller. I was wondering how I would be able to write the code for that view controller? I tried creating a new file > objective-c class, but I dont know how to link them together? any help?
If you've made that other controller in the storyboard, you just change the class of that controller to your new class that you made. You do this in the identity inspector.
Use navigation controller to navigate between your view's, You have to make an IBACTION method fot the button. In which you will navigate the view you want by pushviewcontroller.
Please see this link...
How to push viewcontroller ( view controller )?
It implies that which class has to be initialized and what is the nib name of this class. We should not do anything in this block, until you need that your code to be executed before viewDidLoad/viewWillAppear.
Turns out that there is no code necessary to get a button to direct you to another view controller that you set up. You have to declare the button obviously in the #interface part, connect the button with it's code, and then you have to use an action connection from the button to the next view controller you want the button to activate. I have used a modal connection personally, mainly because I'm not sure what a push connection is or what it does... But Ya I figured it out! Hope this helps to any other people who need this!
Related
Lets say I have an instance of ViewA on window. ViewA has a button on it. When the button is pressed, I want to hide ViewA and show ViewB. What kind of controller(s) would be involved with this? Is there a controller for the view and the window? If so, who handles the event?
Note: This is for OS/X, not iOS.
Here is a sample project that demonstrates use of NSViewController:
https://developer.apple.com/library/mac/#samplecode/ViewController/Introduction/Intro.html
Perhaps it will help you to search more effectively by giving you the right terms to use.
My app dynamically generates buttons. When the button is clicked it creates a table linked to it. I have all the table interfaces (navigation controllers, etc.) set up in storyboard. However, my main view is the home screen where the user creates buttons. Since the button isn't already there, how do I set it up so that it creates a new instance of the tableview outlined in my main storyboard? Is there a "prototype button" in storyboard? The "#selector" action for the generated button is pointing to this IBAction:
-(IBAction)generateTable:(id)sender {
}
Can someone help me fill in the remaining code?
Also, the home screen view controller is already set up in Storyboard, with the arrow next to it.
EDIT: this picture might help understand my problem a better.
http://i.imgur.com/MdT4i1P.png
Found the answer myself quite easily. All you have to do is make a segue (with an identifier) in Storyboard from your ViewController to the ViewController you want it to connect to, then in the IBAction, just add the following.
-(IBAction)generateTable:(id)sender
{
[self performSegueWithIdentifier:#"GoToTable" sender:sender];
}
So I've got this "save" button in my main view controller that I would like to move into a different view controller (WriterViewController). After doing this, my custom view controller class isn't able to respond to any of the button events. Not sure what im doing wrong here but here some screenshots:
Save button is first in my main view controller. I'll be moving it to the view controller to the right (WriterViewController).
As you can see, after moving the button into the intended view controller, the view controller has a custom class set to "WriterViewController".
I then ctrl + click and drag the save button so that i can link up it's "Touch Up Inside" event to the "saveEntry" method.
A screenshot of my WriterViewController.h file.
And the implementation.
Doing the same exact step for the main view controller did work and i was able to log my message. However, it wouldn't work for the custom view controller.
Any thoughts?
Thanks for reading!
Why not just make the save button from scratch for WriterViewController? It's not hard to drag out a UIButton and set it's text to "Save."
Regardless, have you clicked on the button in the scene and viewed the connection's inspector to make sure the connections are what you'd expect? It seems obvious, but sometimes the connections can get all screwed up if you forget to clean them up. (ie. you copy a button over, connections and all, and things don't act as you think they should.)
I'm having some trouble figuring out how to use the Storyboard correctly. My main issue being Modal segues. I have a viewcontroller which I'm trying to display modally (far right in image below). But it just isn't showing. The prepareForSegue is firing correctly.
It does work when I change the segue from a Modal to a Push though.
I'm calling the segue using
performSegueWithIdentifier:#"FirstRunSegue" sender:self
Here is the visual segue setup I have at the moment
When I hover over the Excaimation mark, the following error is displayed:
I am kind of new to Storyboarding, so I'm hoping that someone could explain why the modal segue isn't working and how I would get it to work. The nasty thing is that it is a requirement for the viewcontroller to be in the Storyboard, otherwise I'd just initialize the controller and display it manually.
Regards,
EZfrag
Edit 1:
OK, I managed to figure out why the segue is not being displayed. It is kind of stupid, because it works for a push. It seems that I cannot call a modal segue from the appdeletegate's startup function. Push works fine, but not modal. Confirmed it with a new project.
Is there someone that can explain why this is so?
Regards,
EZFrag
You can only use the push segue with a UINavigationController, but it looks like you are trying to use it between two regular UIViewContoller. If you want to change the way the animation looks, use a custom segue and write your own transition.
Sorry for the complicated title, but it's hard to explain.
This is the hierarchy I have:
Custom View
Custom View
Push Button
Box
WebView
WebView
The way my code works, is that the 'Box' has a 'setContentView' to one of the 2 WebViews shown above. So basically the Box can have a different WebView at any time.
I have the Push Button, which I want to assign to 'Go Back' on the WebView. But I need this button to 'Go Back' on the WebView which is within the Box.
So whenever the WebViews are switched around, the Push Button should link itself to whichever WebView is in the Box, and visaversa.
Is this even possible?
Thanks in advance everyone!
If you had an IBOutlet for your box (called theBox) defined in whichever custom view your button's action method is in, you can just use this in that action method:
[(WebView *)self.theBox.contentView goBack];
So whenever the WebViews are switched around, the Push Button should
link itself to whichever WebView is in the Box, and visa versa.
Why not use a more conventional arrangement? Make the view controller the button's target, and have the action in the view controller take whatever action is appropriate. In this case, that would be adding the appropriate web view to the box.
Views normally don't know anything about how the application works. They just do what the controller tells them to do.