如何更改方法中的detailViewController
我有一个正在执行很多功能的视图,当我完成时,我想更改为 newViewcontroller 。如果我在哪里从根视图执行此操作,我只需调用。
NewPageViewController *newDetailViewController = [[NewPageViewController alloc] initWithNibName:@"NewPageViewController" bundle:nil];
detailViewController = newDetailViewController;
但我需要从我的旧细节(右侧)开始,
我正在从右侧下载 splitview iPad 应用程序中的文件,下载文件后,我需要在我的方法中将 splitview 的右侧更改为新的 nib 文件,以便我可以打开和编辑该文件
有人能以正确的方式指出我吗?
现在我有:
-(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 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.
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UISplitViewController
类上有一个NSArray *viewControllers
属性。该数组中的第一项是您的主 VC,第二项是详细 VC。将此属性重新分配给包含相同主 VC 但新详细信息 VC 的新数组:UISplitViewController 的 API 参考: http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewController_class/Reference/Reference.html
注意:不要尝试更换主 VC - 它通常会以某种方式出现严重错误。 我尝试了很多方法来替换master,它总是以某种非常烦人的方式出错。不过替换细节VC就可以了!
There is an
NSArray *viewControllers
property on theUISplitViewController
class. 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:API ref for UISplitViewController: 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 ways of replacing the master, it always went wrong in some very annoying way. Replacing the detail VC is fine though!
从 iOS8 开始,您可以在 UISplitViewController 上使用
-showDetailViewController:sender:
方法。请参阅 关于 UISplitViewController 的 Apple 文档。As of iOS8 you can use the
-showDetailViewController:sender:
method on the UISplitViewController. See the Apple docs on UISplitViewController.正如 @chris 提到的,您可以使用 iOS 8 及更高版本的 UISplitViewController 的 Delegate,这是最好的方法。
As @chris mentioned you can the use Delegate of UISplitViewController for iOS 8 and above which is the best possible way.