iphone - 检测导航 Controller 何时弹出到根目录

标签 iphone

这是我的代码:

SignupController* signupController = [[SignupController alloc] initWithNibName:@"SignupController" bundle:nil];
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];

    self.navigationController.title = @"MyNavController";

    [self.navigationController pushViewController:signupController animated:YES];
    [signupController release];

不幸的是,对我来说,调用pushViewController不是同步的,因此下一行([signupController release])会立即执行。

我需要检测signupController是否已弹出回根目录,以便我可以从注册 Controller 获取数据并进行注册或登录。

有什么想法吗?

谢谢

最佳答案

使用委托(delegate)模式回调主 Controller ,让它知道注册 Controller 即将退出。在导航 Controller 释放注册 Controller 之前复制其值。

// SignupController.h
@protocol SignupDelegate;
@interface SignupController : UIViewController {
    id <SignupDelegate> delegate;
    NSString *name;
}
@property (nonatomic, assign) id <SignupDelegate> delegate;
@property (nonatomic, retain) NSString *name;
@end
@protocol SignupDelegate
- (void) signupControllerDidFinish:(SignupController *)controller;
@end

// SignupController.m
@implementation SignupController
@synthesize delegate;
@synthesize name;

- (void) viewWillDisappear:(BOOL)animated {
    [self.delegate signupControllerDidFinish:self];
}
@end

// YourViewController.m
- (void) signupSelected {
    SignupController *signup = [[SignupController alloc] initWithNibName:NSStringFromClass([SignupController class]) bundle:nil];
    signup.delegate = self;
    [controller.navigationController pushViewController:signup animated:YES];
    [signup release];
}

- (void) signupControllerDidFinish:(SignupController *)signup {
    NSLog(@"Signup with name %@", signup.name);
}

关于iphone - 检测导航 Controller 何时弹出到根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2437461/

相关文章:

iphone - 请求发送获取错误 : [CFString release]: message sent to deallocated instance 0x6a83e00

iphone - 如何从 native iPhone 应用程序连接到远程数据库

ios - self.canDisplayBannerAds 与约束冲突

ios - iPhone、iPod touch、iPad 发展差异

iPhone SSL 客户端证书不起作用

iphone - sqlite,选择查询不起作用

ios - iPhone CGContext : drawing line with two different colors

iphone - 如何使用 Core Location 检测精度误差幅度

ios - 在 webViewDidFinishLoad 上,我在 swift3 中获得了额外的内容高度

ios - 从 UITableView 中删除自定义 View