From view 1 to view 2 - objective-c

I am stuck in my code. I can't make it to go to the other view when a user logins.
I have a class UILoginClass (Tableviewcontroller) And a class ImageViewController (viewcontroller).
Check image below.
I want to get from UILoginClass to ImageViewController but i can't make it. Anyone help?

1) Create a "push" segue from the view controller of the login screen to the image view controller (press ctrl and drag from source view controller icon to the destination view controller).
2) Give that segue an identifier (click on the seque in IB --> attributes inspector --> identifier. It is just a string identifier that allows you to initiate that segue when you want to.
3) In code, when the login is validated, call performSegueWithIdentifier:sender: with the identifier you gave to the segue.

It sounds like what you want is a push segue from Login Class to Image View Controller. In the Xcode storyboard you add a segue by ctrl-clicking in the source and dragging to the destination. Be sure to give the segue a name. Then in the Login Class you can call the UIViewController method performSegueWithIdentifier:sender:.
Oh, and you can get rid of the push segue from your navigation controller to Image View Controller.

Related

Create back button

How do I create a custom back button on one of my storyboards, when I do a segue and I say push it creates a back button on Mac with but when I do a modal or model it does not create a back button?
Modally presented view controllers do not automatically get close buttons.
self.navigationController.leftBarButtonItem = ...
A pushed view controller will automatically create a back button if the navigation controller is shown.
You will have to create your own back button. In the view controller that you have presented via the modal transition, you have to put a toolbar on it. Put it at the top and if using autolayout set the constraints top, both sides and height. Then place a barbuttonitem in the toolbar. You can select a system button like done or cancel. Make sure the new view controller is the class that you created. Now you can control drag from the barbuttonitem to your .h file and connect an IBAction. Call it dismiss or something like that. In that method call [self dismiss viewcontroller:animated completion:nil]. This will bring you back to the original view controller. I am not a my computer right now so I am not sure the exact wording of the dismiss method, but it will auto fill for you. Good luck.
As Douglas explained, you need to create property of the button (UIButton or BarButtonItem) and in the viewcontroller .m file connect
- (IBAction)backButton:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
with the button. This will dismiss the current view controller and bring you back to the previous one :)

Segue from Custom Cell (dynamic Prototype Cell)

Im using the Storyboard to create my UI.
I have a SplitViewController. The MasterViewController holds a TableViewController where I created a CustomCell with Custom Design.
The Cells are shown pretty good with my data.
The point is: The Custom Cell also holds an Info-Button, with should Popup a little 300x88 TableViewController with some data.
If the Cells in my MasterViewController->TableViewController where a Static one, I just would drag & drop a Segue from the Info-Button to my Popup-TableViewController.
But sadly I cant do this with a dynamic Prototype Cell... I just get the error:
Couldn't compile connections ... >> anchor >> UIButton...
So how can I implement this?
Kind Regards.
Define a manual segue dragging the whole master view onto the detail view, then add a manual target/action to your custom info button and perform the manual segue there. Of course you must set a segue identifier in the storyboard to later reference it in the code, IB will tell you if you forget to.
Instead of connecting and creating segue from individual cells, you can connect all those segues from the View Controller button, lying below your view in your storyboard. In this case, you will have multiple segues and none of them will be individually connected to cells. And when segues are ready, you can use this method for moving on to the next View Controller depending on which cell is tapped from the tableView.
[self performSegueWithIdentifier:#"yourSegue" sender:nil];
You just have to check which cell is tapped and then perform the appropriate Segue on tap using the above code and the respective segue identifier. The prepareForSegue method will be called immediately after this method is called.
Look out for the yellow button as shown below your View Screen in your storyboard.
Drag and drop a segue from that button onto the View Controller that you want to connect.
Hope this helps.

Create a storyboard segue that isn't attached to any UI element?

I'm trying to trigger a storyboard segue from a UI element which isn't in my storyboard (in this case, it's a UIAlertView). As such, I can't draw the arrow from any of the existing components in my storyboard.
What's the proper way to deal with this situation? I need a segue with an identifier, so that I can call it from the relevant UIAlertView button.
You can add your segue by right click + drag from your source controller to your destination controller in your Storyboard. Then just click on the created segue and set the identifier.
You can trigger your segue programmatically like this:
// Note: In this example self is the source controller
// (the controller that holds the segue)
[self performSegueWithIdentifier:#"mySegue" sender:self];
Here is a screenshot you can use as a reference:

How to intergrate the created view controller into the storyboard?

I have a view controller along with .xib created and also a story board. Now i want to have this viewcontroller's view to appear in the storyboard between the navigation bar and the tableview. I thought of dragging a new view controller and have that class point to the view controller i created. Is this solution correct?
Yes that is correct, drag a view controller from the object pallete, change the class name to your view controllers class name and party on. Hook up any segues in the story board you need to it.

StoryBoard Navigation

I have one problem, I have my first view controller and when i push a button to connect with my host to check if the user is registered.. but when i push the button the storyboard pass the next view and after check the user...
So i'm trying pushViewController with code, but i dont know how push a view that is inside the storyboard.
Here is the code : http://pastie.org/3025806
You have to connect the first view with the second view and choose push. It's important to connect the first view and the second view, NOT the Button and the second view.
Edit: I've read your question again. If you change that it will work. If you connect the button and the view controller the push action will be executed directly.
The following is just a tip ;o)
Click on segue, which links to the second view. You have to give a name to that segue so change the identifier name to something like "loginDone". (Open the right menu for that ;o))
Now you can do this after you checked your login form:
[self performSegueWithIdentifier:#"loginDone" sender:self];