【问题标题】:Use pushViewController within app Delegate在 app Delegate 中使用 pushViewController
【发布时间】:2014-07-24 20:53:37
【问题描述】:

您好,我想在应用委托中使用此代码

  ChatController *chatController = [[AppDelegate appDelegate] instantiateViewControllerWithIdentifier:@"GroupController"];
                                            chatController.targetUserid = userid;


                                         [self.navigationController pushViewController:groupChatController animated:YES];

如何从 appdelegate 推送 viewcontroller 我的意思是让上面的代码工作 因为 self.navigationcontroller 不起作用:$

【问题讨论】:

  • 如果您使用故事板,请使用此链接stackoverflow.com/questions/23102978/…
  • 如果您使用的是 XIB,请使用此链接 stackoverflow.com/questions/20742745/…
  • 你确认 self.navigationController == nil 了吗?可能调用这段代码的ViewController不在navigationController下。
  • 我的意思是上面发布的这段代码可以写在appdelegate中因为我希望用户看到推送通知,如果推送通知上面的代码将用户发送到聊天控制器@tyt_g207

标签: ios uinavigationcontroller


【解决方案1】:

在您的委托文件中编写并定义此函数,

- (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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多