几个小时以来,我一直在脑海中喋喋不休。我正在尝试UserProfileViewController
在我的应用程序上创建一个可以处理喜欢、书签等的程序。它将接收来自子控制器的 access_token:LoginViewController
我有LoginViewController
工作。它将 UIWebView 启动到远程系统。远程系统处理登录并接收作为用户 ID 的 access_token。
我已经在我的文件中设置了一个委托LoginViewController
来传回数据,但我想我想要UserProfileViewController
.
这是我想象的 UserProfileViewController.m 的样子,但显然它不起作用:
@synthesize access_token = _access_token;
- (NSString *) access_token // Getter
{
if(!_access_token)
{
_access_token= [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"];
if (!_access_token)
{
LoginViewController *loginViewController = [[LoginViewController alloc] init];
loginViewController.delegate = self;
[self.navigationController pushViewController:loginViewController animated:YES];
// I need the access_token here but it won't arrive until delegate_AccessToken is called by LoginViewController
}
}
return _access_token;
}
// received from LoginViewController
- (void) delegate_AccessToken: (NSString *) aAccess_token
{
// now it's too late to use this in the Getter
}
- (IBOutlet *) likes: (id) sender
{
[self likeThis: sender access_token: _access_token];
}
什么时候打电话LoginViewController
来获取 access_token 的好时机?