我在第二页有UITableview
然后我尝试导航到第三页,但问题是我的代码无效。这是AppDelegate.m文件和SecondViewController.m文件的代码,
Plz检查代码并给我建议我做错了什么
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 Navigation
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;
}
请指导我。
感谢。
答案 0 :(得分: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];