我有一个 UIViewController ,它嵌入在导航控制器中并以模态方式呈现:
//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);
但是我在AuthRootController类中创建的委托有问题:
@protocol AuthRootControllerDelegate
@required
-(void)authRootControllerDidEnd:(UINavigationController *)sender;
@end
@interface AuthRootController : UINavigationController {
id<AuthRootControllerDelegate> delegate;
}
@property (nonatomic, assign) IBOutlet id delegate;
@end
实施:
@implementation AuthRootController
@synthesize delegate;
-(void)userDidCancelController:(UINavigationController *)sender{
if (self.delegate && [self.delegate conformsToProtocol:@protocol(AuthRootControllerDelegate)]) {
[self.delegate authRootControllerDidEnd:sender];
}
}
@end
当我使用方法时
-(void)authRootControllerDidEnd:(UINavigationController *)sender
它没有被触发。有什么想法吗?
答案 0 :(得分:1)
您是否声明您的委托符合AuthRootControllerDelegate? conformsToProtocol测试查看委托是否声明一致性,它不进行任何类型的逐个方法检查。因此,即使您在委托上实现了authRootControllerDidEnd:,conformsToProtocol仍然可以返回NO。
答案 1 :(得分:0)
在您的界面中,您没有声明它是实现委托协议,您需要修改您的接口声明,如下所示:
@interface AuthRootController : UINavigationController<AuthRootControllerDelegate> {