How to use segue to pass taken photo - ios

I want to pass a photo taken in the first view controller to a second view controller. I want the user to take the photo in the first view controller and then crop in in the second view controller and then save.. So its like.. User take photo→crop→save. I just want to do this simple task but taking me days to get the segue go right.. Is segue the best way to do this? or is there a more easier way to do this task. I am a beginner in objective -c so its making me confused with segues and all the stuff.

You need to implement prepareForSegue:sender: in the source view controller. This will give you access to the destinationViewController via the passed storyboard. Then you can set the image so its available when the destination view controller is displayed.

As far as segue is concerned you need to create a segue arrow using storyboard by dragging arrow from first view controller to second view controller, and most importantly you need to give the segue an identifier or name.
For firing you segue you may do it programatically, like:
[self performSegueWithIdentifier:#"ShowSecondScreen" sender:self];
For handling things when segue is fired you need to write prepareForSegue() method, you may pass any object from current viewController to next viewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"ShowSecondScreen"])
{
SecondViewController *secondViewController = segue.destinationViewController;
secondViewController.imageObj = image;
}
}

Related

Pass data between parent view controller and a second navigation controller using button

I have created a signup form in the parent controller and integrated a navigation view controller. Then I connected both the controllers through push segue.
I am stuck with how to transfer data from UITextField in the parent view controller to the navigation controller using the click event of the button placed on the signup form.
Anybody please help me.
Thanks
When a segue is triggered, before the visual transition occurs, the storyboard runtime invokes prepareForSegue:sender: method of the current view controller.
By implementing this method, you can pass any needed data to the view controller that is about to be displayed.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"StoryboardIDOfViewControllerThatWillBeShown"])
{
YourViewController *destinationViewController = segue.destinationViewController;
destinationViewController.dataToPass = _yourTextField.text;
}
}
The best practice is to give each segue in your storyboard an unique identifier. This identifier is a string that your application uses to distinguish one segue from another.
Here is the full description of Passing Data Between View Controllers.

Open different ViewControllers from the same TableViewCell (Like facebook notifications)

Here's the issue, I'm trying to make an app that receives updates for different data in the same TableView (like facebook, lets say), that's not the issue however. All data has the same format, the thing is when you click on a row I want to open the corresponding view, I can identify the correct view to display. I try to use the following.
NavigationController.PushViewController (DestinationViewController, false);
When it gets triggered the objects that I created on the storyboard for the DestinationViewController appear to be null, and all the "glue" code is on the ViewDidLoad or ViewWillAppears (which is supposed to have every object instantiated)
I'm using Tab Bar Navigation Model.
PS: If I use the app and enter to my DestinationViewController it works.
So who knows an approach or has an example of something like this, or something that will get me near the place i want to go?
If you use
NavigationController.PushViewController (DestinationViewController, false);
I believe you need to allocate the view controller before you use it with
DestinationVC *vc = [DestinationVC alloc] init];
Correct me if im wrong everyone.
Also if you are using storyboards and have control dragged to different views, you should use the method
[self.navigationController performSegueWithIdentifier:#"" sender:self];
Then you can use the prepareForSegue method.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"whatYouNamedItInTheStoryboard"]) {
// do stuff for this segue
} else if ([segue identifier] isEqual.......) {
}
}
Hopefully this helps your problem.
You might want to post an image of your storyboard.
I solve the issue kinda like Michael and Paul, says.
Declare a public Attribute on the ViewController.
Then passed the current ViewController to the table source, on the RowSelected Method i put the selected value on the public property of the viewController
And in the PrepareForSegue method i check which type of data it is so i can assign the appropiate segue on the segue.DestinationViewController and pass the data.
I don't know if this is the best approach but, it works good.

How to use segues

I'm creating an app in Xcode that currently consist of a Navigation Controller a Table View Controller and a regular View Controller.
I'm using StoryBoard and have created a segue between the table view and the regular view controller. In the navigation bar I have a button that I've dragged to the view controller in the StoryBoard. When I click at the button, the new View Controller is viewed like it suppose to. I then tried to pass data from the table view controller, see below:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"läggTill"])
{
// Get reference to the destination view controller
AddPlayerViewController *apv = [segue destinationViewController];
[apv.myTextField setText:#"hello"];
}
}
The segue identifier is "läggTill", but the code inside the if-statement is not executing.
Two questions:
What is wrong with this approach?
Is this the best approach when using StoryBoards? Can I pass data via viewWillDisappear?
Can I use segues to pass data back to the table view controller from the view controller?
It makes all the sense in the world to pass your data in the prepareForSegue:sender:. I would not recommend passing data in viewWillDisappear because it just makes it messy and it reduces readability + it becomes harder to keep track.
I think your string comparison is not working! Put an NSLog for your identifier string see on the console. I have a feeling it might not like the "ä" character in comparison.
About your last question, as Gabriel.Massana pointed out, for passing data back, using delegate is the way to go.
Note 1: Another problem I noticed is a possible typo you might have "apv" and "avc".
Note 2: Another reason for it failing is that you are setting the TextField before viewDidLoad gets called on your destination controller. I suggest that pass it as string and in the viewDidLoad of your destination, set the text to your TextField.

Creating an array of view controllers?

I'm brand new when it comes to app development so this might be a stupid question.
So i have made a UI table. It is customizable, as in users can insert or delete rows. I want to allow users to click on a table cell and it'll direct them to another view controller. All the view controllers will look the same for each cell (sorta like a template). Any idea how to implement this using storyboard?
Appreciate it!
You do not need an array of view controllers. All you need is one view controller, which gets instantiated when the user clicks the cell to navigate to it, and gets deallocated as soon as the user closes the screen to go back to your main view controller.
All you need to implement this in your storyboard is adding a push segue from a cell or a button in your main view controller to your "detail" view controller. When the segue gets triggerred, your code gets a chance to configure the newly created "detail" view controller in the prepareForSegue:sender: method, before the controller's view appears on the screen. This is the place where you customize the data that shows up in the detail view (presumably, depending on the particular row in the table that has triggered the segue).
Here is a link to a good tutorial explaining how to build a master-detail application with Xcode and storyboards.
In storyboard you create a viewcontroller that will display the data after a cell has been selected, you will only need one and not an array. Link it from the tableviewcontroller to the new viewcontroller. Click the segue in Xcode and in the inspector give it a unique identifier.
tableView:didSelectRowAtIndexPath: will get called when you select a cell, here you can perform the segue:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedObject = ... // store the object that was selected
[self performSegueWithIdentifier:#"mySegue" sender:self];
}
In your tableviewcontroller you make sure you implement prepareForSegue:sender:. Here you can hand over the correct model object to populate your destination viewcontroller with data.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"mySegue"])
{
MyDetailViewCotroller *controller = [segue destinationViewController];
controller.dataObject = self.selectedObject;
}
}
Check out this example code from Apple (does not used Storyboard though): http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007416

iOS: Storyboard Segue loads before class method call

I have two scenes. A regular, full-screen iPad view and another popover view. Tapping a button loads the popover view with no problems. In the popover view I have a button that will perform some action and is also linked to a storyboard modal transition.
The idea is that pressing the button from the popover view will save the user's selection state and send that data to the main view. I have no issues with the data saving, that works just fine.
The issue I am having is that when I press the button from the popover view, the main view's viewDidLoad method actually completes before the popover view's IBAction method does. So the main view gets the data, but since the view already loaded it is not able to update the label in time.
I tried creating multiple popover view scenes and added multiple buttons to the main view that will link to these new scenes. The weird part is that some of them work just fine. Some of them will perform the IBAction method and then it transitions back to the main view via a modal transition. There seems to be no rhyme or reason why one loads before the other.
I suppose a possible solution would be to perform the transition manually within the IBAction method of the popover view. I am definitely new to this so there may be something fundamental about transitions that I am missing.
In the view controller of view on which the button is present... When segue is going to be performed. You can pass data in
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:#"YOUR_SEGUE_NAME_HERE"])
{
// Get reference to the destination view controller
YourViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object];
}
}
This method is called before the view is loaded..
If you are calling a popover so the main screen should not call viewDidLoad method because the main view still on the back. It should be calling the viewWillAppear and the viewDidApper methods instead.
Can you check this? I think you should refresh the main screen after one of these two methods are called.
Give it a try and tell me the results.

Resources