0

UITableview在第二页然后我尝试导航到第三页,但问题是我的代码不起作用。这是 AppDelegate.m 文件和 SecondViewController.m 文件
的代码,请检查代码并给我建议我做错了什么

SecondViewController.m 文件代码

 - (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
     {

         ThirdViewController *third = [[ThirdViewControllerr alloc] initWithNibName:     @"ThirdViewControllerr" bundle:nil];

         ForthViewController *forth = [[ForthViewControlle alloc] initWithNibName: @"ForthViewController" bundle:nil];

                   if(indexPath.row==0)
                    {
                         [[self navigationController] pushViewController:third animated:YES];

                     }                    

                    if(indexPath.row==1)
                     {
                       [[self navigationController] pushViewController:forth animated:YES];

                     }

在 AppDelegate.m 文件中,我使用 UITableview 在女巫中编写 Secondviewcontroller 的代码,我还初始化了 AppDelegate.m 文件中的 UINavigationController。如果有人有想法尽快回复我,
不使用 AppDelegate.m 文件中的 UINavigationController 可能UItableview 导航

AppsDelegate.m 文件

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[MobileViewController alloc]   initWithNibName:@"MobileViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
       return YES;


        self.window1=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
      self.viewController1=[[HealthCalculatorsViewController alloc]initWithNibName:@"HealthCalculatorsViewController" bundle:nil];
        UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:_viewController1];
        self.window1.rootViewController=nav1;
       [self.window1 makeKeyAndVisible];
        return YES;
        }

请指导我。
谢谢。

4

1 回答 1

0

将此添加到您的 Appdelegate.h

UINavigationController * navController;  

这在你的 Appdelegate.m

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        FirstViewController * viewPhone =[[FirstViewController alloc]initWithNibName:@"FirstViewController_iPhone" bundle:nil];
        navController=[[UINavigationController alloc]initWithRootViewController:viewPhone];
    }
    else
    {
        FirstViewControllerController * viewPad =[[FirstViewControllerController alloc]initWithNibName:@"FirstViewController_iPad" bundle:nil];
        navController=[[UINavigationController alloc]initWithRootViewController:viewPad];
    }
    navController.navigationBar.tintColor = [UIColor blackColor];
    self.window.rootViewController=navController;

在您的按钮上单击

- (IBAction)Btn_Pressed:(id)sender {
    SecondViewController * second=[[SecondViewController alloc]init];
    if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)    
        second = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];    
    else        
        second = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPad" bundle:nil];

       [self.navigationController pushViewController:lagrangae animated:YES];

}

如果您不想要导航栏,只需将其隐藏

[[self navigationController] setNavigationBarHidden:YES animated:YES];
于 2013-10-04T04:57:55.123 回答