Iphone UIBarButtonim到情节提要视图
我在一个单独的xib文件中有一个UIBarButton项,但当按下该按钮时,我想将其带到我的故事板上的一个视图 我可以从故事板视图(当按下圆形rect按钮时)转到单独的自定义xib文件视图。但我不能回去(使用圆形矩形按钮或uibarbuttonim)Iphone UIBarButtonim到情节提要视图,iphone,ios,xcode,storyboard,uibarbuttonitem,Iphone,Ios,Xcode,Storyboard,Uibarbuttonitem,我在一个单独的xib文件中有一个UIBarButton项,但当按下该按钮时,我想将其带到我的故事板上的一个视图 我可以从故事板视图(当按下圆形rect按钮时)转到单独的自定义xib文件视图。但我不能回去(使用圆形矩形按钮或uibarbuttonim) 有人能帮忙吗?如果您使用此代码从xib创建视图: -(IBaction)button { MainViewController *viewOther = [[MainViewController alloc] initWithNibNam
有人能帮忙吗?如果您使用此代码从xib创建视图:
-(IBaction)button {
MainViewController *viewOther = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:viewOther.view];
[THISViewController release];
}
然后,只需在新的子视图控制器中执行此操作即可将其删除,并“返回”到情节提要上的视图:
[self.view removeFromSuperview];
然而,我认为这根本不是最好的处理方法。我会将新的viewController
呈现为modalViewController
,然后在使用以下方法完成时将其取消:
[self dismissModalViewControllerAnimated:YES];
提交:
-(IBaction)button {
MainViewController *viewOther = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:viewOther animated:YES];
}
然后使用以下命令将其释放:
[self dismissModalViewControllerAnimated:YES];
然而,这仍然不是最好的方法。最好的方法是在
MainViewController
中创建一个委托,然后让情节提要视图控制器将自己指定为MainViewController
的委托。然后,当按下按钮时,MainViewController
应通知其代表(情节提要视图控制器)将其关闭,然后情节提要视图控制器将关闭MainViewController
。但是,这需要花费一点时间来解释,尤其是当您不熟悉创建协议时。您是在推序列还是以模式显示它?您不能将单独的XIB文件中的视图放入情节提要中有具体原因吗?@MarkS。如何将单独的XIB文件放入序列图像板?@JamesPaolantonio当从序列图像板转到单独的XIB文件时,我使用以下代码:-(iAction)按钮{MainViewController*viewOther=[[MainViewController alloc]initWithNibName:@“MainViewController”bundle:[NSBundle mainBundle]];[self.view addSubview:viewOther.view];[THISViewController release];}非常适合转到单独的xib文件。只是无法使用我添加到我的单独xib中的UIBarButtonim返回到序列图像板ViewController是要从序列图像板视图实例化新视图,还是要转到序列图像板上已显示的视图?