您好,我想在app delegate
中使用此代码 ChatController *chatController = [[AppDelegate appDelegate] instantiateViewControllerWithIdentifier:@"GroupController"];
chatController.targetUserid = userid;
[self.navigationController pushViewController:groupChatController animated:YES];
如何从appdelegate推送viewcontroller 我的意思是使上面的代码工作 cuz self.navigationcontroller不起作用:$
答案 0 :(得分:2)
在委托文件中编写并定义此函数,
- (void)pushViewControllerFrom:(UIViewController*)controller {
ChatController *chatController = [[AppDelegate appDelegate] instantiateViewControllerWithIdentifier:@"GroupController"];
chatController.targetUserid = userid;
[controller.navigationController pushViewController:groupChatController animated:YES];
}
现在使用您想要的UIViewController
中的委托对象调用该函数,
[appDelegateObject pushViewControllerFrom:self];
请注意,
您可以像这样创建appDelegateObject
,
#import "AppDelegate.h"
AppDelegate *appDelegateObject = (AppDelegate *)[UIApplication sharedApplication].delegate;