【发布时间】:2014-03-06 17:25:02
【问题描述】:
我正在尝试从我的应用委托中设置视图控制器的委托。 但它不起作用。
AppDelegate.m:
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:nil];
SFLoginViewController * LoginVC = (SFLoginViewController *)[sb
instantiateViewControllerWithIdentifier:@"Login"];
LoginVC.delegate = self;
SFLoginViewController.m
- (IBAction)Login:(id)sender {
NSLog(@"%@",self.delegate); //returns nil (!!)
//It should call the delegate method here
[[self delegate] LoginSucceeded];
}
有什么帮助吗?
【问题讨论】:
-
添加 self 作为代理后,是否将 LoginVC 添加到 AppDelegate 中的视图层次结构? SFLoginVC.m 中哪里调用 NSLog?
-
@Greg 视图层次结构是什么意思?我在 UIbutton 触摸事件中调用它(触发登录过程)..
-
如果您发布更多相关代码可能会
-
我认为,NSLog 语句是在 loginVC.delegate = self; 之前执行的。声明,因此 - SFLoginViewController 对象被创建并触发 NSLog 消息,在您设置委托之前。 SFLoginViewController 中的 NSlog 语句在哪里?
-
@JohnWoods 我已经更新了代码..
标签: ios objective-c uistoryboard appdelegate