【问题标题】:PushViewController and Popview Controller on uinavigation bar from initial view controllerPushViewController 和 Popview Controller 在初始视图控制器的导航栏上
【发布时间】:2012-07-20 10:07:46
【问题描述】:

我是 iPhone 新手。我对 uinavigation 控制器有一点困惑,即我希望在该视图控制器中的初始视图控制器中有一个导航栏,当我们单击时,导航栏中有一个按钮,它将从那里推送另一个视图控制器(第二个视图控制器)是一个后退按钮,如果我们单击我想弹出该视图控制器并返回到初始视图控制器。如果有人知道这一点,请帮助我。如果你用一些代码解释它会更好地理解我们。

我写的以下代码,到目前为止,这里显示模态视图控制器和关闭模型视图控制器正在工作,但 pushview 控制器和 popview 控制器不工作

在appDelegate中我是这样写的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        //create a window
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        //biblePlayerController is an instance of BiblePlayerViewController class and then set the biblePlayerController as a rootViewController to the window
        self.biblePlayerController = [[BiblePlayerViewController alloc] initWithNibName:@"BiblePlayerViewController" bundle:nil];

       navigationController = [[UINavigationController alloc]initWithRootViewController:self.biblePlayerController];

      // self.window.rootViewController = self.biblePlayerController;
        [self.window addSubview:navigationController.view];  
//make the window visible
        [self.window makeKeyAndVisible];

        return YES;   

}   

//In initial View controller there is a navigation on that there is a download button code for that is 

//BiblePlayerViewController.m
 UIBarButtonItem *downloadButton = [[UIBarButtonItem alloc] initWithTitle:@"Download" style:UIBarButtonItemStylePlain target:self action:@selector(gotoProgressViewController:)];
        self.navigationItem.rightBarButtonItem = downloadButton;

- (IBAction)gotoProgressViewController:(id)sender {
    @try {

        //ShowProgressViewCont is initialized with the nibName
        showProgressViewController = [[ShowProgressViewCont alloc]initWithNibName:@"ShowProgressViewCont" bundle:nil];

        //UINavigationController is initialized with the rootViewController showProgressViewController
        navigationController = [[UINavigationController alloc]initWithRootViewController:showProgressViewController]; 

        //The transition style of the navigationController is set to UIModalTransitionStyleCrossDissolve
        navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        //Presents a modal view managed by the given view controller to the user.Here navigation Controller that manages the modal view.
        [self presentModalViewController:navigationController animated:YES];
      //  [navigationController pushViewController:showProgressViewController animated:YES];
    }
    @catch(NSException * e){NSLog(@"Exception At10: %s %d %s %s %@",__FILE__,__LINE__,__PRETTY_FUNCTION__,__FUNCTION__,e);}@finally{}
}

在上面的代码中,presentModalViewController 可以正常工作,但 pushViewController 不能正常工作。如果有人知道这一点,请帮助我..

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    假设你在 ParentViewController 中并且通过按下 Child Btn 你想去 ChildViewController。

    - (void) childBtnPressed : (id) sender
    {
         ChildViewController *makeNewObject = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
         [self.navigationController pushViewController:makeNewObject animated:YES];
         [makeNewObject release];
    }
    

    现在在您的 ChildViewController.m 文件中,将其写入 Back Btn 操作以返回父视图控制器。

    - (void) backBtnPressed : (id) sender
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
    

    【讨论】:

      【解决方案2】:

      点击导航栏中的按钮,推送下一个视图

      - (IBAction)NextViewAction:(id) sender
      {
           NextViewController *NxtView = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
           [self.navigationController pushViewController:NxtView animated:YES];
           [NxtView release];
      }
      

      从 NextViewController 弹出

      [self.navigationController popViewControllerAnimated:YES];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-19
        • 1970-01-01
        • 2011-09-18
        • 1970-01-01
        相关资源
        最近更新 更多