无法导航到下一页iPhone
我是iPhone开发者的新手 我的应用程序中有无法导航到下一页iPhone,iphone,ipad,uitableview,uinavigationcontroller,rootview,Iphone,Ipad,Uitableview,Uinavigationcontroller,Rootview,我是iPhone开发者的新手 我的应用程序中有4页面,我的应用程序是viewBasedApplication 我将我的第一页(LicAppViewController)设置为RootViewController,以下是我的代码 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWi
4
页面,我的应用程序是viewBasedApplication
我将我的第一页(LicAppViewController
)设置为RootViewController
,以下是我的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[LicAppViewController alloc] initWithNibName:@"LicAppViewController" bundle:nil] autorelease];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
在按钮上单击“我正在导航到第二页”(PlanPage
)
到目前为止,它工作正常,但当我在第2页中选择一行时,它会使我的应用程序崩溃,我想导航到第3页(DetailPlanPage
),下面是我的代码
DetailPlanPage *nextController = [[DetailPlanPage alloc] initWithNibName:@"DetailPlanPage" bundle:nil];
[self.navigationController presentModalViewController:nextController animated:TRUE];
但当我写作时,这句话:
[self.navigationController pushViewController:nextController animated:YES];
而不是:
[self.navigationController presentModalViewController:nextController animated:TRUE];
很好用。(我不确定,但我的应用程序崩溃可能是由于基于视图的应用程序造成的。)
提前感谢试试看
[self presentModalViewController:nextController animated:YES];
您还需要将nextController的委托设置为self,并添加一个委托函数来解除模态视图控制器。最重要的区别在于语义。模态视图控制器通常表示用户必须提供某些信息或执行某些操作。此链接对其进行了更深入的解释:
当您呈现模态视图控制器时,系统将在进行呈现的视图控制器和所呈现的视图控制器之间创建父子关系。具体而言,进行显示的视图控制器会更新其modalViewController属性,以指向其显示的(子)视图控制器。类似地,显示的视图控制器更新其parentViewController属性,以指向显示它的视图控制器。还有一个。首先设置rootview控制器 删除该代码
[self.window addSubview:navigationController.view];
包括
self.window.rootViewController = navigationController;
在当前的模态视图控制器中,您可以这样尝试
yourview *detailViewController = [[yourview alloc] initWithNibName:@"yourview" bundle:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(dismiss)];
detailViewController.navigationItem.leftBarButtonItem = doneButton;
UINavigationController *nav;
nav=[[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
[self presentModalViewController:nav animated:YES];
[detailViewController release];
[doneButton release];
-(void) dismiss
{
[self dismissModalViewControllerAnimated:YES];
}
老兄,你真厉害,我的代码运行得很好,我可以在我的新页面上看到导航栏,但里面没有后退按钮。运行得很好,有没有类似后退按钮的样式?给我这个答案,我会接受你的回答,使用backbutton image..UIBarButtonItem*backbutton=[[UIBarButtonItem alloc]initWithImage:[UIImage ImageName:@“back button.png”]样式:uibarbuttonimstyleplain目标:自我操作:@selector(disease)]autorelease];self.navigationItem.leftBarButtonItem=backButton;是的,它在起作用,那是我的错。任何方式都可以获得帮助。@Krunal:应该可以使用模态视图控制器。我有一个较新版本的Xcode,所以我尝试创建一个简单的单视图应用程序,我可以提供一个模态视图控制器。你们得到了和崩溃相关的任何输出吗?我按照Rams的回答,它工作得很好,谢谢你们的帮助。
yourview *detailViewController = [[yourview alloc] initWithNibName:@"yourview" bundle:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(dismiss)];
detailViewController.navigationItem.leftBarButtonItem = doneButton;
UINavigationController *nav;
nav=[[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
[self presentModalViewController:nav animated:YES];
[detailViewController release];
[doneButton release];
-(void) dismiss
{
[self dismissModalViewControllerAnimated:YES];
}