【发布时间】:2013-01-30 21:49:04
【问题描述】:
我已经花了整整 2 天的时间试图弄清楚如何使用 NSViewControllers 来创建多视图应用程序。
这就是我的工作。
我有 2 个视图控制器和 MainMenu.xib 的窗口。 我还有一个 AppController,它是两个视图控制器的委托。
当我启动应用程序时,首先映入眼帘的是 MainMenu.xib 的窗口视图,其中包含一个按钮。单击此按钮时,会向 appController 发送 IBAction 并要求 SecondViewController 显示它的 nib。至此,一切正常,nib文件显示正确。
在 secondViewController 上,有另一个按钮将另一个 IBAction 发送到 appController 并要求显示 FirstViewController 但没有任何反应, 没有崩溃,没有警告......任何帮助将不胜感激...... 提前感谢您的耐心等待...
这是 AppController.h 的代码:
#import <Foundation/Foundation.h>
#import "SecondViewController.h"
#import "FirstViewController.h"
@interface AppController : NSObject
@property (strong) IBOutlet NSWindow *mainWindow;
@property (strong) IBOutlet SecondViewController *secondViewController;
@property (strong) IBOutlet FirstViewController *firstViewController;
- (IBAction)secondButtonfromsecondViewControllerClicked:(id)sender;
- (IBAction)buttonClicked:(id)sender;
@end
这里是 AppController.m 的代码:
#import "AppController.h"
@implementation AppController
@synthesize mainWindow = mainwindow;
@synthesize secondViewController;
@synthesize firstViewController;
- (IBAction)buttonClicked:(id)sender {
NSLog(@"button from second View Controller clicked");
self.secondViewController = [[SecondViewController
alloc]initWithNibName:@"SecondViewController" bundle:nil];
self.mainWindow.contentView = self.secondViewController.view;
[self.secondViewController.view setAutoresizingMask:NSViewWidthSizable |
NSViewHeightSizable];
}
- (IBAction)secondButtonfromsecondViewControllerClicked:(id)sender {
NSLog(@"button from first ViewController clicked");
self.firstViewController = [[FirstViewController
alloc]initWithNibName:@"FirstViewController" bundle:nil];
self.mainWindow.contentView = [self.firstViewController view];
}
@end
好吧,任何人都可以帮助我,我只需要一个单视图应用程序,它显示第一个 ViewController,第一个 viewController 上的按钮将我带到第二个视图控制器,第二个按钮将我带回我的第一个 viewcontroller。 ..我已经花了一个多星期的时间......徒劳无功...... PS:我不想要 mainMenu.xib 窗口或选项卡上的任何按钮。
【问题讨论】:
-
您想要使用视图控制器的任何特殊原因(除了可能习惯在 iOS 中使用它们)?这听起来像是一个标签视图的完美工作。甚至只是以编程方式交换视图。
-
好的,你已经检查了明显的;该操作未在 Interface Builder 中连接?
-
哇,至少有一些答案......
标签: cocoa multiview nsviewcontroller