0

This is what i have so far in my code: i am using storyboard...

- (IBAction)OpenActionSheetButton:(id)sender {


UIActionSheet *actionsheet = [[UIActionSheet alloc]initWithTitle:@"There is no going back, are you sure???" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Continue" otherButtonTitles:nil, nil];
[actionsheet showInView:self.view];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:  (NSInteger)buttonIndex
{
   if(buttonIndex == 0)
  {
    if(buttonIndex == 0)
        [self performSegueWithIdentifier:@"openView" sender:self];
    UIViewController *controller =  [self.storyboard


    instantiateViewControllerWithIdentifier:@"storyboardViewIdentifier"];
    //storyboardViewIdentifier is the ViewController identifier you specify in the storyboard

    //PUSH
    [self.navigationController pushViewController:controller animated:YES];
    //Modal
    [self presentViewController:controller animated:YES completion:Nil];
}
}

/// My New Code:

- (IBAction)OpenActionSheetButton:(id)sender {


UIActionSheet *actionsheet = [[UIActionSheet alloc]initWithTitle:@"There is no going back, are you sure???" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Continue" otherButtonTitles:nil, nil];
[actionsheet showInView:self.view];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
    if(buttonIndex == 0)
        [self performSegueWithIdentifier:@"openView" sender:self];

}
}

I have no errors but when i push "Continue", the app force=closes because its not hook up right. My Q is, what should i jave dont in my storyboard? Drag from the viewcontroller that has the actionsheet to the viewcontroller that i want the "continue" button to navigate to(open)? That is what i want to happen. Thanks guy i am very new to developing and i am trying to learn. You guys help alot :)

user212803
  • 37
  • 7
  • A few things here: what exactly is your error (what does the stack trace look like)? Also, you're calling `performSegueWithIdentifier:sender` and then continuing on to instantiate a view controller, push it, and present it modally. I'm guessing you really only want 1 of those 3 things. – ppilone Jun 27 '13 at 15:43
  • Ok, i will send a link to a picture what i think you mean by the "Stack Tace". After i have the code typed. My question is: What should i have done in story board to make it work? The rest of your question was a little over my head :( sorry – user212803 Jun 28 '13 at 06:33
  • http://s1276.photobucket.com/user/GiovanniMunoz97/media/l_zpsa0ff75da.png.html – user212803 Jun 28 '13 at 06:44
  • The stack trace will be in the Xcode console after your application crashes. It'll provide the exception being thrown and the calls that led up to the call that threw an exception. – ppilone Jun 28 '13 at 19:23
  • 2013-06-28 21:12:08.189 SpellCaster5[471:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'openView'' *** First throw call stack: (0x1c91012 0x10cee7e 0xf4e42 0x2dbb 0x3f033d 0x10e2705 0x162c0 0x16258 0xd7021 0xd757f 0xd66e8 0x45cef 0x45f02 0x23d4a 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1beb7e3 0x1beb668 0x12ffc 0x271d 0x2645) libc++abi.dylib: terminate called throwing an exception (lldb) – user212803 Jun 29 '13 at 03:14

1 Answers1

0

You want to pay attention to "Receiver () has no segue with identifier 'openView'" line of your stack trace. You're trying to perform a segue with identifier 'openView' but a segue with that identifier does not exist in your storyboard.

Open your main story board and select the segue that connects your view controllers. Select the Attributes Inspector and set the identifier of your segue.

enter image description here

You'll also want to remove the following lines:

UIViewController *controller =  [self.storyboard

instantiateViewControllerWithIdentifier:@"storyboardViewIdentifier"];
//storyboardViewIdentifier is the ViewController identifier you specify in the storyboard

//PUSH
[self.navigationController pushViewController:controller animated:YES];
//Modal
[self presentViewController:controller animated:YES completion:Nil];

When you perform a segue, UIKit will handle presenting the destination view controller with the animation you defined in your storyboard. You definitely don't want to try presenting it multiple times.

I'd suggest taking a look at the View Controller Programming Guide for iOS, specifically "Working with View Controllers in Storyboards".

ppilone
  • 1,082
  • 1
  • 10
  • 16
  • Ok!Thanks! I updated my new code ^^^ I got no errors but it still crashes. I need to make sure i changed the segue ID right. This is what i did: I typed in the "Identifier" box 'openView', and "Style"= 'Modal', and transition= Default-animates (Doubt that matters at all) Am i doing this right? Thanks for helping a noob :) – user212803 Jul 01 '13 at 06:25
  • It'd be helpful to see the stack trace again. If it's the same issue make sure the view controller owning the action sheet was loaded from the same storyboard, as the docs state for `performSegueWithIdentifier:sender:` "The view controller that receives this message must have been loaded from a storyboard. If the view controller does not have an associated storyboard, perhaps because you allocated and initialized it yourself, this method throws an exception." – ppilone Jul 01 '13 at 14:07
  • Ok, here is the stack line: 2013-07-02 21:23:40.029 SpellCaster5[833:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'openView'' *** First throw call stack: (0x1c91012 0x10cee7e 0xf4e42 0x2f6a 0x3f033d 0x10e2705 0x162c0 0x16258 0xd7021 0xd757f 0xd66e8 0x45cef 0x45f02 0x23d4a 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1beb7e3 0x1beb668 0x12ffc 0x28cd 0x27f5) libc++abi.dylib: terminate called throwing an exception (lldb) – user212803 Jul 03 '13 at 03:39
  • Also, i cant find how i would check if it was loaded from the same storyboard. Is the way i named the segue correct? Maybe i created the seque the wrong way in the first place? – user212803 Jul 03 '13 at 03:43
  • How are you initializing the instance of your SWViewController that calls `performSegueWithIdentifier:sender:`? You can also check by putting a breakpoint before you try and perform the segue and inspecting the `storyboard` property on self. Also, have you tried the answer from http://stackoverflow.com/questions/11874200/nsinvalidargumentexception-receiver-has-no-segue-with-identifier this SO post? – ppilone Jul 03 '13 at 14:16
  • Hey man, im sure you dont remember this post but thanks alot for you help bro. Account was lost – user212803 Nov 21 '13 at 23:58