2013-04-25 192 views
1

我已將代碼添加到我的didFinishLaunchingWithOptions方法中,以在通知中打開應用程序時打開特定視圖。我爲該視圖的導航欄添加了「解除」按鈕。我試圖讓該按鈕在解除模態視圖後將用戶帶到主屏幕。當用戶點擊按鈕時,應用程序崩潰。這裏有人有什麼想法嗎?關閉模式視圖控制器

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // This prevents the UA Library from registering with UIApplcation by default when 
    // registerForRemoteNotifications is called. This will allow you to prompt your 
    // users at a later time. This gives your app the opportunity to explain the benefits 
    // of push or allows users to turn it on explicitly in a settings screen. 
    // If you just want everyone to immediately be prompted for push, you can 
    // leave this line out. 
    // [UAPush setDefaultPushEnabledValue:NO]; 

    //Create Airship options dictionary and add the required UIApplication launchOptions 
    NSMutableDictionary *takeOffOptions = [NSMutableDictionary dictionary]; 
    [takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey]; 

    // Call takeOff (which creates the UAirship singleton), passing in the launch options so the 
    // library can properly record when the app is launched from a push notification. This call is 
    // required. 
    // 
    // Populate AirshipConfig.plist with your app's info from https://go.urbanairship.com 
    [UAirship takeOff:takeOffOptions]; 

    // Set the icon badge to zero on startup (optional) 
    [[UAPush shared] resetBadge]; 

    // Register for remote notfications with the UA Library. This call is required. 
    [[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | 
                 UIRemoteNotificationTypeSound | 
                 UIRemoteNotificationTypeAlert)]; 

    // Handle any incoming incoming push notifications. 
    // This will invoke `handleBackgroundNotification` on your UAPushNotificationDelegate. 
    [[UAPush shared] handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey] 
         applicationState:application.applicationState]; 

    // self.tabBarController = [[UITabBarController alloc] initWithNibName:@"KFBViewController" bundle:nil]; 
    KFBViewController *rootView = [[KFBViewController alloc] initWithNibName:@"KFBViewController" bundle:nil]; 
    KFBNavControllerViewController *navController = [[KFBNavControllerViewController alloc] initWithRootViewController:rootView]; 
    navController.delegate = rootView; 
    UIViewController *aboutUs = [[AboutUs alloc] initWithNibName:@"AboutUs" bundle:nil]; 
    KFBNavControllerViewController *navController1 = [[KFBNavControllerViewController alloc] initWithRootViewController:aboutUs]; 

    UIViewController *contactUs = [[ContactUs alloc] initWithNibName:@"ContactUs" bundle:nil]; 
    KFBNavControllerViewController *navController2 = [[KFBNavControllerViewController alloc] initWithRootViewController:contactUs]; 

    UIViewController *kyfb = [[KYFB alloc] initWithNibName:@"KYFB" bundle:nil]; 
    KFBNavControllerViewController *navController3 = [[KFBNavControllerViewController alloc] initWithRootViewController:kyfb]; 

    // UIViewController *rsfm = [[RSFM alloc] initWithNibName:@"RSFM" bundle:nil]; 
    // KFBNavControllerViewController *navController4 = [[KFBNavControllerViewController alloc] initWithRootViewController:rsfm]; 

    // UIViewController *li = [[LegislatorInfo alloc] initWithNibName:@"LegislatorInfo" bundle:nil]; 
    // KFBNavControllerViewController *navController5 = [[KFBNavControllerViewController alloc] initWithRootViewController:li]; 

    // UIViewController *events = [[Events alloc] initWithNibName:@"Events" bundle:nil]; 
    // KFBNavControllerViewController *navController6 = [[KFBNavControllerViewController alloc] initWithRootViewController:events]; 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    //self.viewController = [[KFBViewController alloc] initWithNibName:@"KFBViewController" bundle:nil]; 
    //self.window.rootViewController = self.viewController; 
    self.tabBarController = [[KFBTabBarViewController alloc] init]; 
    self.tabBarController.viewControllers = @[navController, navController1, navController2, navController3]; 
    // self.tabBarController.customizableViewControllers = nil; 

    self.window.rootViewController = self.tabBarController; 
    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 

    // If application is launched due to notification,present another view controller. 
    UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 

    if (notification) 
    { 
     ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc] initWithStyle:UITableViewStylePlain]; 
     WebViewController *wvc = [[WebViewController alloc]init]; 
     [actionAlerts setWebViewController:wvc]; 
     KFBNavControllerViewController *navController7 = [[KFBNavControllerViewController alloc] initWithRootViewController:actionAlerts]; 
     actionAlerts.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc ] initWithTitle:@"Dismiss" style:UIBarButtonItemStyleBordered target:self action:@selector(dismiss:)]; 
     [self.window.rootViewController presentViewController:navController7 animated:NO completion:nil]; 
    } 

    return YES; 
} 



- (IBAction)dismiss 
{ 
    [self.window.rootViewController dismissViewControllerAnimated:NO completion:nil]; 

} 

回答

2

你呈現從窗口的根視圖控制器該控制器是self.tabBarController,但是從導航控制器貶。試試這個:

[self.window.rootViewController dismissViewControllerAnimated:NO completion:nil]; 

編輯後:

我現在看到的問題 - 你欄按鈕項的操作方法是解散:(帶冒號),而你實現,沒有冒號解僱。他們需要是一樣的。

+0

這實際上是我最初的樣子,它也會崩潰應用程序。 – raginggoat 2013-04-25 16:12:44

+0

@ user2029585,你是否收到任何錯誤信息? – rdelmar 2013-04-25 16:18:00

+0

沒有錯誤信息。 – raginggoat 2013-04-25 16:24:48

1

用p.e調用它。通過觸摸向上的內部功能的UIButton

[self dismissModalViewControllerAnimated:YES];