Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在应用程序代理中使用pushViewController_Ios_Uinavigationcontroller - Fatal编程技术网

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