P253-254 respondsToSelector returning false on iPad


#1

The list of possessions wasn’t reloading data after saving a new possession, so I tracked it down to the “respondsToSelector” check…

[code]- (IBAction)save:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@“Save Button Clicked”);

if ([delegate respondsToSelector:@selector(itemDetailsViewControllerWillDismiss:)]) {
    NSLog(@"delegate Responds To Selector");
    [delegate itemDetailViewControllerWillDismiss:self];
}

}[/code]

When I take out that “if” statement, it runs fine, on both the iPhone and iPad simulators …

[code]- (IBAction)save:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@“Save Button Clicked”);
[delegate itemDetailViewControllerWillDismiss:self];

}[/code]

What would cause that respondsToSelector to keep returning false?
Is that check really necessary, since it’s working fine without it?


#2

You have a typo - you check:

But then send the message to the selector:

The key difference being you check itemDetails… instead of checking itemDetail… (s/Details/Detail/). In this book example it works fine without the check, but you can’t assume that in general the user will always give you a delegate that implements that method (remember, you declared it optional in the ItemDetailViewControllerDelegate protocol).