xcode 如何在方法中更改 detailViewController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5448252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:40:00  来源:igfitidea点击:

How do you change the detailViewController in a method

iphonexcodeipadview

提问by Chris B

I have a view that is doing a lot of functions and when I get to the point that I am done I want to change to a newViewcontroller. if I where to do this from the rootview I just call.

我有一个视图正在执行很多功能,当我完成时,我想更改为newViewcontroller. 如果我从 rootview 中执行此操作,我只需调用。

NewPageViewController *newDetailViewController = [[NewPageViewController alloc] initWithNibName:@"NewPageViewController" bundle:nil];
detailViewController = newDetailViewController;

But I need to do it from my old detail (the right side)

但我需要从我的旧细节(右侧)

I am downloading a file in a splitview iPad app from the right side and after the file is downloaded I need to in my method change the right side of the splitview to a new nib file so I can open and edit the file

我正在从右侧的 splitview iPad 应用程序中下载文件,下载文件后,我需要在我的方法中将 splitview 的右侧更改为新的 nib 文件,以便我可以打开和编辑文件

Can someone point me in the right way.

有人可以以正确的方式指出我。

Now I have :

我现在有 :

-(void)changeView { 

    ListController *newDetailViewController = [[ListController alloc] initWithNibName:@"ListController"bundle:nil]

    NSArray *viewControllers = [NSArray arrayWithObjects:[splitViewController.viewControllers objectAtIndex:0], newDetailViewController, nil];

    splitViewController.viewControllers = viewControllers;
    [viewControllers release];

}

-(void)downloadfile {
 //I do all my work and get the file.
NSLog(@"I need to change views now.");


                [self changeView];

}

I don't get any errors but the right side view is not changing.

我没有收到任何错误,但右侧视图没有改变。

回答by chris

As of iOS8 you can use the -showDetailViewController:sender:method on the UISplitViewController. See the Apple docs on UISplitViewController.

从 iOS8 开始,您可以使用-showDetailViewController:sender:UISplitViewController 上的方法。请参阅UISplitViewController 上Apple 文档

回答by occulus

There is an NSArray *viewControllersproperty on the UISplitViewControllerclass. The first item in this array is your master VC, the second in the detail VC. Re-assign this property to a new array containing the same master VC but a new details VC:

类上有一个NSArray *viewControllers属性UISplitViewController。此数组中的第一项是您的主 VC,详细信息 VC 中的第二项。将此属性重新分配给包含相同主 VC 但新的详细信息 VC 的新数组:

// don't forget to set the delegate of myNewDetailViewController appropriately!
myNewDetailViewController.delegate = ...

NSArray newVCs = [NSArray arrayWithObjects:[uiSplitVC.viewControllers objectAtIndex:0], myNewDetailViewController, nil];

uiSplitVC.viewControllers = newVCs;

API ref for UISplitViewController: http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewController_class/Reference/Reference.html

UISplitViewController 的 API 参考:http: //developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewController_class/Reference/Reference.html

N.B: do not try replacing the master VC-- it usually goes horribly wrong somehow. I tried many many waysof replacing the master, it always went wrong in some very annoying way. Replacing the detail VC is fine though!

注意:不要尝试更换主 VC——它通常会以某种方式出现可怕的错误。我尝试了很多替换 master 的方法,但总是以一些非常烦人的方式出错。不过,更换细节 VC 很好!

回答by daris mathew

As @chris mentioned you can the use Delegate of UISplitViewController for iOS 8 and above which is the best possible way.

正如@chris 提到的,您可以在 iOS 8 及更高版本中使用 UISplitViewController 的委托,这是最好的方法。

 -(void)showDetailViewController:(UIViewController *)vc sender:(nullable id)sender NS_AVAILABLE_IOS(8_0);