Ios 在应用程序代理中使用pushViewController
你好,我想在应用程序代理中使用此代码Ios 在应用程序代理中使用pushViewController,ios,uinavigationcontroller,Ios,Uinavigationcontroller,你好,我想在应用程序代理中使用此代码 ChatController *chatController = [[AppDelegate appDelegate] instantiateViewControllerWithIdentifier:@"GroupController"]; chatController.targetUserid = userid;
ChatController *chatController = [[AppDelegate appDelegate] instantiateViewControllerWithIdentifier:@"GroupController"];
chatController.targetUserid = userid;
[self.navigationController pushViewController:groupChatController animated:YES];
如何从appdelegate推送viewcontroller
我的意思是让上面的代码工作
因为self.navigationcontroller不工作:$在代理文件中编写并定义此函数
- (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;
如果您正在使用故事板,请使用此链接如果您正在使用XIB,请使用此链接您是否验证self.navigationController==nil?可能,调用此代码的ViewController不在navigationController下。我的意思是,上面发布的此代码可以写入appdelegate中,因为我希望用户看到推送通知,如果推送通知将上述代码发送给chatcontroller@tyt_g207