1

I am really confused about segues. There are so many different ways to change the current ViewController and I don't know which to use and mix them up.

What I currently have, is a MainViewController. On this I have 4 Buttons. The first button is connected with a Show (e.g Push) Segue. On the other side of the Segue is a Navigation Controller with a View Controller. Now this works with no additional code.

Now my first Question. The Navigation Controller will never be shown, right? Only the View Controller will be shown. But if I want to add a Navigation Item Button on the right side to go back to the first View Controller how should I do it? I need to add the button programmatic like this:

UIBarButtonItem *leftBackToPreviousScreenButton = [[UIBarButtonItem alloc]
                                              initWithTitle:@""
                                              style:UIBarButtonItemStylePlain
                                              target:self
                                              action:@selector(back)];

- (void)back
{
    [self performSegueWithIdentifier:@"ExitEventOverview" sender:self];
}

Is this right?

Now the next step is, that I need to open another View to edit details of an event which are shown in the previous View as a table. When I click on the table row the Edit View should open and I need to pass the event object. How do I do this with segues? After finishing editing how can I add programmatic a Cancel and Save button to the Edit View do return to the Overview of all Events?

Pascal
  • 2,175
  • 4
  • 39
  • 57
  • These questions are very broad, I'd suggest trying to narrow your problem down to a single, more specific question. Have you read [the "Using Segues" section of the View Controller Programming Guide for iOS](https://developer.apple.com/library/prerelease/ios/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html#//apple_ref/doc/uid/TP40007457-CH15-SW1)? – Stuart Aug 05 '15 at 06:40
  • Why doesn't the navigation controller hold everything? – Wain Aug 05 '15 at 06:46
  • Well the problem is that there are many tutorials etc. but each shows something else. Now I don't know which is the best way to do the thing I described. I mean I currently have a project in which the segues work. But the code still feels wrong :) – Pascal Aug 05 '15 at 06:52
  • in initially it happen , every tutorial does not give proper answer, some tutorials may be given correctly else part we need to customize what ever we need – Anbu.Karthik Aug 05 '15 at 07:06

2 Answers2

2

your coding is fine and add following line also

UIBarButtonItem *leftBackToPreviousScreenButton = [[UIBarButtonItem alloc]
                                          initWithTitle:@""
                                          style:UIBarButtonItemStylePlain
                                          target:self
                                          action:@selector(back)];

// add this line 
self.navigationItem.rightBarButtonItem = leftBackToPreviousScreenButton;

- (void)back
{
// if you want to pop on previous view controller

 [self.navigationController popViewControllerAnimated:YES];

}

in last question you need to customize ,but if you need to pass the data between two view controller use this link

Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
1

Don't forget to implement a UINavigationController and put assign your UIViewController with 4 buttons as root view controller. Show segues presents the navigation bar but the others don't, in that case you need to manage it and to add it.

To show the details, just override the method prepareForSegue:sender to do so :

[self performSegueWithIdentifier:@"NextSegue" sender:nil];

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"NextSegue"]) {
        NextViewController *nextViewController = (NextViewController*)[segue destinationViewController];
        nextViewController.details = self.details;
        // nextViewController.details is the property "details" declared in your NextViewController.h file, you just give it the value you want to send from your present one.
    }
}
user3783005
  • 542
  • 1
  • 9
  • 20