我有一个导航 Controller ,它是我的应用程序的 Root View Controller 。这是我的主屏幕。我有一个分割 View Controller ,其主视图列出位置,详细 View 显示 map 上的位置。我想将分割 View Controller 推送到导航 Controller ,但它抛出一个错误,指出分割 View Controller 无法推送到导航 Controller ,它必须是应用程序的 Root View Controller 。 所以我很努力地尝试。
MyAppDelegate *myappdelegate= [[UIApplication sharedApplication] delegate];
UISplitViewController * vc= [[UISplitViewController alloc] init];
vs.viewControllers = [NSArray arraywithObjects......
....
myappdelegate.window.rootViewController= vc;
这有效。它显示了没有预期动画的分割 View Controller 。当我关闭分割 View Controller 时,我执行相同的步骤。我正在创建一个带有主屏幕 Nib 的导航 Controller ,并再次将其设置为我的应用程序委托(delegate)的 window.rootviewController 。 并且它再次成功加载主屏幕。
但我怀疑这是实现这一目标的正确方法。有更合适的方法吗?
而且我无法释放分割 View Controller 的子 Controller 。我在子 Controller 的释放方法上设置了一个断点。它没有被捕获。我假设当我将应用程序的 Root View Controller 设置为导航 Controller 时,旧的 Root View Controller (分割 View Controller )必须与其 subview Controller 一起释放。 然后我在关闭分割 View Controller 时尝试了下面的代码。
UISplitViewController *oldviewcontroller= (UISplitViewController*) myappdelegate.window.rootViewController;
for (UIViewController *child in oldviewcontroller.viewControllers)
{
[child release];
}
//Setting the navigation controller as window.rootviewController again in here.
此代码抛出错误“[UIImageView __viewDidDisappear:]: 无法识别的选择器发送到实例 0x7d....”
我认为由于已经释放了 View ,viewdidDisappear 事件上没有 imageview。
简而言之,我的问题是我是否使用正确的方法来实现这一目标?如果是这样,我怎样才能成功释放所有 subview Controller ?
最佳答案
终于找到办法了。我可能发现了错误。我所做的就是砍断我所坐的 Twig 。我正在释放我当前所在的 View Controller :)当 viewdidDisappear 被调用时,没有这样的 View Controller 。因为我已经把它扔到太空了。以下是我的工作步骤。我希望它对某人有用。但我无法忍受苹果可能会拒绝我的应用程序。我希望找到一个合适的方法。
这是我交替使用分割 View Controller 和导航 Controller 作为窗口 Root View Controller 的最终工作方式。
首先我在AppDelegate接口(interface)中定义了NavigationController和SplitViewController属性。
AppDelegate.h
@property (assign,nonatomic) UINavigationController * NC;
@property (assign,nonatomic) UISplitViewController *SVC;
其次,我在 AppDelegate didFinishLaunch 事件上分配新创建的 NC。
AppDelegate.m
//Creating my main screen controller
//Creating my navigation controller with my view controller instance. Then
self.NC= my_navigation_controller;
self.window.rootViewController= self.NC;
第三,创建一个 splitview Controller 并设置为应用程序的 Root View Controller
MyMainScreen.m
-(void) OpenSplit()
{
//Creating my master view controller of SVC
//Creating my detail view controller of SVC
//Creating my SVC;
AppDelegate * app_delegate= [[UIApplication sharedApplication] delegate];
app_delegate.SVC= newly created my SVC;
app_delegate.window.rootViewController= app_delegate.SVC;
}
第四次在SVC详细 View 的viewDidLoad事件中释放未使用的NC。
MyDetailView.m
- (void) viewDidLoad()
{
...
AppDelegate * app_delegate= [[UIApplication sharedApplication] delegate];
app_delegate.NC= nil; //i dont need it now. i am releasing. Releasing Navigation Controller release as well child controllers. I learned with testing.
}
第五,管理关闭分割 View 功能。我在DetailView中的NavigationBar上使用了UIBarButton。
MyDetailView.m
-(void) closeSplitView
{
//Creating navigation controller with my main screen view controller
AppDelegate * app_delegate= [[UIApplication sharedApplication] delegate];
app_delegate.NC= newly_created_NC;
app_delegate.window.rootViewController= appdelegate.NC;
}
第六,处理主屏幕 viewDidLoad 事件中未使用的分割 View Controller 。
MyMainScreen.m
-(void) viewDidLoad
{
AppDelegate * app_delegate= [[UIApplication sharedApplication] delegate];
app_delegate.SVC= nil; //I am releasing it because i am working with NC now.
}
关于ios - 交替使用分割 View Controller 和导航 Controller 作为窗口 Root View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13685828/