开发者

Method implemented from delegate not triggered

I have a UIViewCo开发者_如何转开发ntroller which is embedded in a navigation controller and presented modally:

//UIViewController
AuthenticationController *auth = [[AuthenticationController alloc] init];

//UINavigationController
AuthRootController *navController = [[AuthRootController alloc]
                                         initWithRootViewController:auth];

navController.navigationBar.topItem.title = @"Anmelden";
navController.delegate = self;

[self presentModalViewController:navController animated:YES];
RELEASE_SAFELY(navController);

However there is something wrong with the delegate I created within the AuthRootController class:

@protocol AuthRootControllerDelegate

@required
-(void)authRootControllerDidEnd:(UINavigationController *)sender;

@end

@interface AuthRootController : UINavigationController {
    id<AuthRootControllerDelegate>  delegate;
}

@property (nonatomic, assign) IBOutlet id delegate;

@end

And the implementation:

@implementation AuthRootController
@synthesize delegate;

-(void)userDidCancelController:(UINavigationController *)sender{
    if (self.delegate && [self.delegate conformsToProtocol:@protocol(AuthRootControllerDelegate)]) {
        [self.delegate authRootControllerDidEnd:sender];
    }
}

@end

When I use the method

-(void)authRootControllerDidEnd:(UINavigationController *)sender

it is not triggered. Any ideas?


Have you declared that your delegate conforms to AuthRootControllerDelegate? The conformsToProtocol test looks at whether the delegate declares conformance, it doesn't do any sort of method-by-method check. So even if you've implemented authRootControllerDidEnd: on your delegate, conformsToProtocol can still return NO.


In your interface you aren't declaring it as implementing the delegate protocol, you need to modify your interface declaration like this:

@interface AuthRootController : UINavigationController<AuthRootControllerDelegate> {
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜