解雇模态视图控制器

时间:2013-04-25 15:25:46

标签: ios modalviewcontroller

我已经在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 个答案:

答案 0 :(得分:2)

您从窗口的根视图控制器(self.tabBarController)中呈现此控制器,但是从导航控制器中解除它。试试这个:

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

编辑后:

我现在看到了问题 - 你的bar按钮项的动作方法是dismiss :(带冒号),而你实现了dismiss而没有冒号。他们需要是一样的。

答案 1 :(得分:1)

用p.e调用它。 UiButton通过Touch Up Inside Function

[self dismissModalViewControllerAnimated:YES];
相关问题