Mladen Kajic
Mladen Kajic

Reputation: 125

UIActionSheet button segue into new ViewController

I'm trying to make the buttons on a UIActionSheet call segues which go to other view controllers. This is the code i have so far and it just crashes. The error message i get is "'Receiver () has no segue with identifier 'Town''"

- (IBAction)CategorizeButton:(id)sender {
UIActionSheet* AS = [[UIActionSheet alloc]initWithTitle:@"Group by"
                                                delegate:self
                                      cancelButtonTitle:@"Cancel"
                                 destructiveButtonTitle:nil
                                      otherButtonTitles:@"Town",@"Title",@"Location", nil];
[AS showInView:self.view];
}

-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        [self performSegueWithIdentifier:@"Town" sender:self];
    }
    if (buttonIndex == 1)
    {
        [self performSegueWithIdentifier:@"Title" sender:self];
    }
    if (buttonIndex == 2)
    {
        [self performSegueWithIdentifier:@"Location" sender:self];
    }
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSString* CategorizeTown = @"Town";
    NSString* CategorizeTitle = @"Title";
    NSString* CategorizeLocation = @"Location";

    if ([[segue identifier] isEqualToString:CategorizeTown])
    {
        CategoryTableViewController* CAT = [segue destinationViewController];
        // blah blah
    }
    if ([[segue identifier] isEqualToString:CategorizeTitle])
    {
        CategoryTableViewController* CAT = [segue destinationViewController];
        // blah blah
    }
    if ([[segue identifier] isEqualToString:CategorizeLocation])
    {
        CategoryTableViewController* CAT = [segue destinationViewController];
        // blah blah
    }
}

Upvotes: 0

Views: 769

Answers (1)

ukim
ukim

Reputation: 2465

In storyboard, select the segue.

enter image description here

Give it an identifier, (in your case, @"Town",@"Title",@"Location")

enter image description here

Upvotes: 2

Related Questions