在 OS X 中使用 NSViewControllers 在视图之间切换
Switching between Views using NSViewControllers in OS X
如何使用视图控制器(借助 IBAction)在多个视图之间切换?
这是我到目前为止编写的代码:
在接口文件中我做了一个IBAction:
-(IBAction)Next;
在实现文件中我这样写:
- (IBAction)Next
{
SecondPopovercontrol *second = [[SecondPopovercontrol alloc] initWithNibName:nil bundle:nil];
[self presentingViewController:second animated: YES completion:NULL]; // This is the step I am facing issues with
}
我无法得到这个 运行- 2 个视图控制器的名称是:WOMPopoverController
和 SecondPopovercontrol
。
错误是:
"No visible @interface for WOMPopoverController declares the selector presenting Viewcontroller:animated:completion"
我是 StackExchange 的新手,所以如果我的问题有任何不一致之处,请告诉我。并且,请指导我如何解决这个问题。
谢谢
presentingViewController
是 UIViewController 的 属性。它持有指向当前 viewController 的 viewController 的指针 ed (如果此 viewController 未由呈现 [=55] 呈现,则为 nil =]).
您的本意是向 self
发送 presentViewController:animated:completion
消息:
[self presentViewController:second animated:YES completion:nil];
(那是'present',不是'presented')
当second
出现时,它的presentingViewController
属性会被设置为这个self,self的presentedViewController
属性会被设置为second
编辑
正如 Jef 所指出的,我错误地认为你正在处理 iOS。在 OSX 上,方法类似。 NSViewController 有一个 presentingViewController
属性 和一个 presentedViewControllers
数组 。您可以使用的各种呈现方式不同:
– presentViewController:animator:
– presentViewController:asPopoverRelativeToRect:ofView:preferredEdge:behavior:
– presentViewControllerAsModalWindow:
– presentViewControllerAsSheet:
无论如何,我认为您需要仔细考虑 NSViewController documentation 以确保您使用的是针对正确平台的正确方法(您的错误方法似乎源自 iOS,而不是OSX).
编辑 2
我制作了一个 small demo app 来展示 NSViewController
在 OSX 上的各种呈现行为,包括一个非常基本的自定义动画对象。
如何使用视图控制器(借助 IBAction)在多个视图之间切换?
这是我到目前为止编写的代码:
在接口文件中我做了一个IBAction:
-(IBAction)Next;
在实现文件中我这样写:
- (IBAction)Next
{
SecondPopovercontrol *second = [[SecondPopovercontrol alloc] initWithNibName:nil bundle:nil];
[self presentingViewController:second animated: YES completion:NULL]; // This is the step I am facing issues with
}
我无法得到这个 运行- 2 个视图控制器的名称是:WOMPopoverController
和 SecondPopovercontrol
。
错误是:
"No visible @interface for WOMPopoverController declares the selector presenting Viewcontroller:animated:completion"
我是 StackExchange 的新手,所以如果我的问题有任何不一致之处,请告诉我。并且,请指导我如何解决这个问题。
谢谢
presentingViewController
是 UIViewController 的 属性。它持有指向当前 viewController 的 viewController 的指针 ed (如果此 viewController 未由呈现 [=55] 呈现,则为 nil =]).
您的本意是向 self
发送 presentViewController:animated:completion
消息:
[self presentViewController:second animated:YES completion:nil];
(那是'present',不是'presented')
当second
出现时,它的presentingViewController
属性会被设置为这个self,self的presentedViewController
属性会被设置为second
编辑
正如 Jef 所指出的,我错误地认为你正在处理 iOS。在 OSX 上,方法类似。 NSViewController 有一个 presentingViewController
属性 和一个 presentedViewControllers
数组 。您可以使用的各种呈现方式不同:
– presentViewController:animator:
– presentViewController:asPopoverRelativeToRect:ofView:preferredEdge:behavior:
– presentViewControllerAsModalWindow:
– presentViewControllerAsSheet:
无论如何,我认为您需要仔细考虑 NSViewController documentation 以确保您使用的是针对正确平台的正确方法(您的错误方法似乎源自 iOS,而不是OSX).
编辑 2
我制作了一个 small demo app 来展示 NSViewController
在 OSX 上的各种呈现行为,包括一个非常基本的自定义动画对象。