【问题标题】:View does not get pushed on button click - Iphone dev点击按钮时视图不会被推送 - Iphone dev
【发布时间】:2013-06-08 04:57:09
【问题描述】:

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

- (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;

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

【问题讨论】:

  • AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate] 中添加演员表AppDelegate

标签: iphone ios uinavigationcontroller pushviewcontroller


【解决方案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 您只需实现您的推送推送方法和您的视图被推送为您想要的。 :)

【讨论】:

    猜你喜欢
    • 2010-11-15
    • 1970-01-01
    • 2011-02-10
    • 2013-01-26
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多