0

我正在尝试从按钮推送视图。该方法在点击时被调用,但视图不会被推送到导航控制器中。下面是按钮点击的代码:

- (IBAction)aboutButtonTapped:(id)sender {
    NSLog(@"dashBoardButtonTapped");
    if (self.aboutView == nil) {
        self.aboutView = [[About alloc] initWithNibName:@"About" bundle:nil];
        [self.navigationController pushViewController:self.aboutView animated:YES];
    }
    else {
        [self.navigationController pushViewController:self.aboutView animated:YES];
    }
}

我想要做的是,当我登录到我的应用程序时,会出现一个带有按钮的选项视图。每个按钮都必须在视图中按下。下面是调用 optionsView 的 ViewController.m 文件中的代码:

self.optionsView = [[Options alloc] initWithNibName:@"Options" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.optionsView];

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.window.rootViewController = self.navigationController;

请告诉我我在这做错了什么?

4

1 回答 1

1

您必须在您的appDelegate 方法中添加一个UIViewcontroller,并使其如下所示:-RootViewcontrollerUInavigationController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

            self.viewController = [[yourViewcontroller alloc] initWithNibName:@"yourViewcontroller" bundle:nil];
            self.navController=[[UINavigationController alloc]initWithRootViewController:self.viewController];


    self.window.rootViewController = self.navController;

    [self.window makeKeyAndVisible];
    return YES;
}

然后,您无需应用每个类创建新的 UInavigationController,您只需实现您的推送推送方法和您的视图被推送为您想要的。:)

于 2013-06-12T07:01:39.827 回答