1

Hi there i want to use this code within the app delegate

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


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

how can i push viewcontroller from appdelegate i mean make the above code work cuz self.navigationcontroller doesnt work :$

Aragunz
  • 511
  • 5
  • 18
  • if u are using storyboard use this link http://stackoverflow.com/questions/23102978/swrevealviewcontroller-without-using-navigationcontroller/23105142#23105142 – Anbu.Karthik Jun 04 '14 at 09:19
  • if u are using XIB use this link http://stackoverflow.com/questions/20742745/navigation-controller-push-view-controller/20742996#20742996 – Anbu.Karthik Jun 04 '14 at 09:20
  • Did you verify that self.navigationController == nil? Maybe, the ViewController that call this code is not under a navigationController. – Duyen-Hoa Jun 04 '14 at 09:26
  • I mean this code as posted above can it be written within appdelegate cuz i want users to see push notification , if push notification the above code to send user to the chatcontroller @tyt_g207 – Aragunz Jun 04 '14 at 09:31

1 Answers1

2

Write and define this function in your delegate file,

- (void)pushViewControllerFrom:(UIViewController*)controller {
    ChatController *chatController = [[AppDelegate appDelegate] instantiateViewControllerWithIdentifier:@"GroupController"];
                                        chatController.targetUserid = userid;
    [controller.navigationController pushViewController:groupChatController animated:YES];
}

Now call the function with your delegate object from the UIViewController of you want,

[appDelegateObject pushViewControllerFrom:self];

Note, You can create appDelegateObject like this,

#import "AppDelegate.h"

AppDelegate *appDelegateObject = (AppDelegate *)[UIApplication sharedApplication].delegate;
Hemang
  • 26,840
  • 19
  • 119
  • 186