I am new to developing apps for iOS devices, and I just tried out storyboard mode. I wanted to know if there was a way to change the function of the button,
for example, I have three pages, and on the first page I have two buttons, one that leads two the next page and a button that leads to the third page?
I would really appreciate an answer. Thanks
Cant you just control drag from the button to the page you want it to lead to? that is how storyboard works.
IMPORTANT: to go back you DO NOT create a button and make drag it back, instead you create a button and set the code for that button to dismiss the view controller.
You can still use the old method in Interface Builder : drag the IBAction to your button.
If you plan to use segues, you have to define the segue name in Properties, and implements - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender method.
Related
I have a login system created. It uses a user ID instead of username and password. I want to make it so when the login button is pressed, it opens another view controller in my storyboard. I already have an if statement checking the user ID to see if it is correct. I just need to know the method to perform. I have tried a few, but I need more explanation of how to use them.
There are a couple of ways to do this. The first is to create a segue that directly links the login button to the new view controller. If you want to do this, right click drag (or control drag) from the button to the new view controller. This should make a grey line going from the first controller to the second one. You can then click on the little circle in the middle of the segue in interface builder to give it a name and specify the type.
Alternatively, if you created the login button with code, or would just like more control over your segues, you can create a generic segue in interface builder, meaning just control drag from one view controller to the other. If you do it this way, YOU MUST NAME THE SEGUE so you have a way to invoke it later. Then you just call [self performSegueWithIdentifier:#"nameOfYourSegue" sender:self]; to make the segue happen.
If you need to configure the new view controller at all or give it any data, this should happen in the prepareForSegue: method.
Here's a link to a nice tutorial on segues:
http://www.appcoda.com/storyboards-ios-tutorial-pass-data-between-view-controller-with-segue/
I Have interesting question.
I have two screens, I need that would be the third screen elements (buttons, label) are static and do not change when you move from one screen to another. .
So MAIN DISPLAY 1 will be change, DISPLAY 2 too , but button and others(label for example) need be static.
Big Thanks for all help, sorry i don't have any code with this problem. Because i don't know how this make...
Ok, so if you have a UI that won't change it's content you have to consider the following:
If the user can navigate from one screen to another, then you will have to create multiple view controllers(it can be done in other ways but this is the easiest and best way to doit) that will have their own UI, that can be easily created in storyboards like this:
Create a new project that use storyboars (you can use the Xcode templates that support your needs)
In your generated storyboard, drag and drop a new UINavigationController, and in the Attributes inspector check the Is initial view controller
Drag another UIViewController into your storyboard, select your navigation controller, hold right click and drag to the newly added view controller, a popup will appear and from that popup select root view controller. Now the newly added view controller will be the first view that the app will display. On this view controller add your UI elements (buttons, labels, etc). If you want another screen to be shown when a user taps on a button, drag another view controller and select the button from which you want to display the next screen, hold right click drag to the newly added view controller, from the popup select push. Now when the user tap on the button the next view controller will be shown and as a bonus because you use iOS, the system will create a back button so that you can go back to your first view controller.
Ok, this is the a basic tutorial from which you can start and expand, but for that you will have to read more, spend nights on google/SO to find solutions, you will learn apple docs by heart and other things that are required so that you can be a great iOS developer.
My the iOS force be with you and Steve Jobs watch your steps.
This is off the top of my head:
you could put a view into your uiwindow and place your static elements there, and then give a transparent background to display1 and display2. then you can have the two displays forward their touches to the background elements to have actions on the buttons. im sorry i dont have any code, but i never tried that ;)
A much better way is to instantiate your ViewController like so:
this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);
Then inside your instantiated View Controller you setup a static variable that holds that instance of the View Controller:
public static StaticViewController staticViewController;
When the Static View Controller fires up for the first time:
staticViewController = this;
Now in the future when you fire up the Static View Controller (from wherever in your app) you can check to see if the StaticViewController.staticViewController variable is null or not.
Use simple if else logic to load it up accordingly:
if (StaticViewController.staticViewController == null) {
StaticViewController.staticViewController staticViewController = this.Storyboard.InstantiateViewController ("StaticViewController") as StaticViewController;
this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);
} else {
if(!StaticViewController.staticViewController.IsBeingPresented) //safeguard against click happy users
this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);
}
You should add the static views to your UINavigationController or whatever controller you are using for managing multiple controllers.
Im new to storyboard. Im trying to create a tableview with static cells (1 section with 2 rows). Now i need to go to different views on taping the rows.
How can i connect the view in Interface builder??
This method is not required as im not passing any data to the next view.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(#"%#",segue.identifier);
}
I need to show static views on tapping the row of the table.
In interface builder im not able to create more than 1 segue for a section.
Open your story board in separate window so that your source code is also seen on display;
Open your *.h file (perhaps that one your main view controller is declared);
In interface builder, drag the event you want to use to your *.h file. xcode will draw something like a placeholder in the place you drag it and when you drop it, it will generate IBaction method for you. Just implement it (using segues or something else) and here you have it.
prepareForSegue is different thing. You may use segues too (think of segue as about descriptor of your controller-to-controller move) but it is a different workflow. There is tons of documentation on this.
I need to create two Segue's from the same button, and then I want to programatically choice which one to use based on device orientation. The problem I'm having is that you can only seem to create one segue from a button to another view so when I add the second one it just changes the first.
How do you add a segue that either isn't linked to a button etc so I can do programatically or how are you supposed to do this. I want to have two views that get dynamically picked based on orientation rather than moving the objects based via code when rotated as there is alot of objects and custom stuff that would make it much simplier just to have two views.
You'd have to trigger the segue manually. Hook up the button to a method, then make two segues, one from each view controller to the other in your storyboard, then give it an identifier in IB, then in your method you can call "performSegueWithIdentifier:".
Additional Info
To make a manual segue, control-click from the view controller object in IB to another view controller and the box will pop up as "Manual Segue". Just make sure it has an identifier.
I would think you could have the button trigger an IBAction wherein you could make a choice based on orientation and then trigger the appropriate segue programmatically.
I added uiviewcontroller subclass in my arc enabled project, i added a button created the ibaction for it and inside it contains no code, all done through interface builder no manual code, but when i am tapping the button i am getting exc_bad_acess. Instrumentation saying its a zombie attack when pressing button. I really dont understand whats going wrong. I created the new project and done the same thing it is working perfectly. Same thing happening when i am defining method to dismiss keyboard (resign first responder).
this generated when i crtl+dragged from button to interface implementation, i choose the ibaction and name and this code is generated.
- (IBAction)pushh:(id)sender;
and the implementation inside .m file
- (IBAction)pushh:(id)sender {
}
thats all ...
Just to wrap up the offline conversation, a couple of thoughts:
Your zombie is undoubtedly a result of the ecnObj falling out of scope. If it's an ivar of the view controller, then that premature release problem goes away.
You do not want to create a new view controller and then use its view in transitionFromView. If you want to transition between view controllers (in iOS5) you should use pushViewController or presentViewController (or if you're using a container view controller, you can pursue transitionFromViewController). See View Controller Programming Guide's discussion of "Presenting View Controllers from Other View Controllers".
My solution was to delete the button iboutlet in ib, also delete the ibaction in ib, and then connect it back.