0

My prepare for segue call keeps causing a crash without any error message. So I use NSLog to track what’s happening. The following line is never reached

NSLog(@"The VCs matched!!: " )

Here is the method

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"enter prepare for segue.");
    NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];

    if ([segue.identifier isEqualToString:SegueIdentifierA]) {
        NSLog(@"Destination to match are: %@, %@ .",segue.destinationViewController,[PaperDetailViewController class] );
        if ([segue.destinationViewController isKindOfClass:[PaperDetailViewController class]]) {
            NSLog(@"The VCs matched!!: " );
            PaperDetailViewController *paperDetailView = (PaperDetailViewController *)segue.destinationViewController;

        }else NSLog(@"NO ONO NO match for %@ AND %@.",segue.destinationViewController,[PaperDetailViewController class] );
    }
    NSLog(@"exit prepare for segue.");

}
learner
  • 11,490
  • 26
  • 97
  • 169

3 Answers3

1

Given the information all I can recommend is that you specify the class for your view controller in the storyboard editor.

enter image description here

DylanVann
  • 483
  • 5
  • 9
1

It would be great to see the stack trace as the comments suggest. That would provide valuable clues. Without them, the most likely culprit is:

NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];

Which is blindly assuming that the sender is a UITableViewCell. If it isn't, you'd see a crash for sure (and we'd see it in the stack trace). If a table selection is what's triggering the segue, than this is safer and easier to read...

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
danh
  • 62,181
  • 10
  • 95
  • 136
0

Sorry for the false alarm. There seems to have been a problem with my Xcode. Xcode just crashed and after I restarted it, everything just work as expected. Thanks and +1 to everyone for helping.

learner
  • 11,490
  • 26
  • 97
  • 169
  • 1
    You should always attempt to provide the full exception message and a stack trace when asking for help with a "crash". There are times when this is not possible for whatever reason, but you should make a reasonable effort at getting that info BEFORE posting your question. (This goes for any language, not just Objective-C.) – Hot Licks Jul 22 '14 at 20:55
  • There really was no trace in my case. Nothing. – learner Jul 22 '14 at 21:18
  • Possible if Xcode was really crashing, but rare even then. (Unfortunately, the stack trace is hard to extract in many cases, but it's well worthwhile to learn how. See the link I posted earlier.) – Hot Licks Jul 22 '14 at 21:22