Guest User

Untitled

a guest
Aug 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. trying to access UINavigationController from within AppDelegate
  2. #import "AppDelegate.h"
  3. #import "ProfileConnection.h"
  4.  
  5. @implementation AppDelegate
  6.  
  7. @synthesize window = _window;
  8. @synthesize navController;
  9.  
  10. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  11. {
  12. // Override point for customization after application launch.
  13. return YES;
  14. }
  15.  
  16. -(void)switchToController:(NSString *)controller animated:(BOOL)animated{
  17.  
  18. NSLog(@"switching to controller %@", controller);
  19.  
  20. // maybe we can do a check to see if a subview exists...and then push or pop accordingly.
  21.  
  22. // switch to the "TableView" view
  23. if( [controller isEqualToString:@"ProfileConnection"]){
  24. NSLog(@"switching to the ProfileConnection view");
  25.  
  26. ProfileConnection *profile = [[ProfileConnection alloc] initWithNibName:@"ProfileConnection" bundle:nil];
  27. [self.navController pushViewController:profile animated:YES];
  28.  
  29. }
  30. }
  31.  
  32. -(void)showConnectionFoundAlert
  33. {
  34. NSString *connectFoundMsg = [[NSString alloc] initWithFormat:@"We found someone we'd think you would like to meet: Tony Davis"];
  35. UIAlertView *connectionFoundAlert = [[UIAlertView alloc] initWithTitle:@"Connection Found" message:connectFoundMsg delegate:self cancelButtonTitle:@"Decline" otherButtonTitles:@"Connect", @"View Profile", @"Save For Later", nil];
  36. [connectionFoundAlert show];
  37. //[connectionFoundAlert release];
  38.  
  39. }
  40.  
  41. -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
  42. {
  43. NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
  44. NSString *alertString = [[NSString alloc] initWithFormat:@""];
  45.  
  46. if([title isEqualToString:@"Decline"])
  47. {
  48. alertString = @"Declied";
  49. }
  50. else if([title isEqualToString:@"Connect"])
  51. {
  52. alertString = @"Connected";
  53. }
  54. else if([title isEqualToString:@"View Profile"])
  55. {
  56. //alertString = @"Profile Viewed";
  57. //NSLog(@"View Profile is being called");
  58.  
  59. [self switchToController:@"ProfileConnection" animated:YES];
  60.  
  61. //UIViewController *profile = [[UIViewController alloc] initWithNibName:@"ProfileConnection" bundle:nil];
  62. //ProfileConnection *profile = [[ProfileConnection alloc] initWithNibName:@"ProfileConnection" bundle:[NSBundle mainBundle]];
  63. //UINavigationController *nav = [[UINavigationController alloc] init];
  64. //[nav pushViewController:profile animated:NO];
  65.  
  66.  
  67. /*UIViewController *profile = [[UIViewController alloc] initWithNibName:@"ProfileConnection" bundle:nil];
  68. UINavigationController *navigation = [[UINavigationController alloc] init];
  69. [navigation pushViewController:profile animated:YES];*/
  70.  
  71. /*
  72. ProfileConnection *profile = [ProfileConnection alloc];
  73. //UIView *current = self.window;
  74. [self.window addSubview:profile.view];
  75. */
  76. /*
  77. [window addSubview:view1.view];
  78. [window makeKeyAndVisible];
  79.  
  80. - (void)goToNextPage {
  81. view2 = [ViewController2 alloc];
  82. UIView *current = self.window;
  83. [self.window addSubview:view2.view];
  84. */
  85.  
  86. }
  87. else if ([title isEqualToString:@"Save For Later"])
  88. {
  89. alertString = @"Saved It";
  90. }
  91.  
  92. UIAlertView *alertStr = [[UIAlertView alloc] initWithTitle:@"" message:alertString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
  93.  
  94. if ([alertString isEqualToString:@""]) {
  95.  
  96. } else {
  97. [alertStr show];
  98. }
  99. }
  100.  
  101. @end
  102.  
  103. #import <UIKit/UIKit.h>
  104. #import "ProfileConnection.h"
  105.  
  106. @interface AppDelegate : UIResponder <UIAlertViewDelegate, UIApplicationDelegate, UINavigationControllerDelegate> {
  107. UINavigationController *navController;
  108. }
  109.  
  110. @property (strong, nonatomic) UIWindow *window;
  111. @property (nonatomic, retain) UINavigationController *navController;
  112.  
  113. -(void)showConnectionFoundAlert;
  114. -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
  115. -(void)switchToController:(NSString *)controller animated:(BOOL)animated;
  116.  
  117. @end
  118.  
  119. ProfileConnection *profile = [ProfileConnection alloc];
  120. [self.window addSubview:profile.view];
  121.  
  122. self.window.rootViewContorller = self.navController;
  123.  
  124. NSLog(@"%@ %@",self.navController, profile);
Add Comment
Please, Sign In to add comment