keji
keji

Reputation: 5990

Segue Headaches in Xcode

I have a tableview and I created a segue to push it to another view controller. Every now an then this segue breaks without me touching it I can guarantee. I didn't even edit the file I put it in.

My Code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *acell = [tableView cellForRowAtIndexPath:indexPath];
    [self performSegueWithIdentifier:@"cellWasSelected" sender:acell];
}



- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"cellWasSelected"])
    {
        if ([sender isKindOfClass:[UITableViewCell class]])
        {
            UITableViewCell *selectedCell = sender;
            ViewController *myDetViewCont = segue.destinationViewController;
            myDetViewCont.navigationItem.title = selectedCell.textLabel.text;
        }
    }
}

First after clicking a cell xcode directs me to the file this segue pushes to. It redirects me here: action:@selector(handleSingleTap:)]; I use this for my images to trigger this: [self.navigationController popToRootViewControllerAnimated:YES]

If I choose in Thread 1 my main view I see the problem is:

[self performSegueWithIdentifier:@"cellWasSelected" sender:acell];

But whats the problem I used this athousand times and it starts crashing without me changing it.

Upvotes: 0

Views: 335

Answers (1)

iMemon
iMemon

Reputation: 1093

Your code don't have any bugs, the problem is somewhere else. May be you have not give the segue an identifier in interface builder. Try this code. It is working on my side, if your files don't have any problem it should run on your side too.

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

NSString* identifier = [segue identifier];

if ([identifier isEqualToString:@"cellWasSelected"]) {
    NSLog(@"Performing Seque");

    if ([sender isKindOfClass:[UITableViewCell class]]) {
        NSLog(@"correct");
        UITableViewCell *selectedCell = sender;
        UIViewController* myDetViewCont = segue.destinationViewController;
        myDetViewCont.navigationItem.title = selectedCell.textLabel.text;
    }
}

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSLog(@"%@",@"Cell Selected");
   UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
   [self performSegueWithIdentifier:@"cellWasSelected" sender:cell];
}

P.S. If you are still having problems you, then may be you are new to storyboard and you need enough knowledge to work on them. http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

Upvotes: 4

Related Questions