我有一个MainWindow.xib文件。我在第一个MainWindow.xib文件屏幕上有一个标签和一个按钮。我有secondview.xib文件,我想加载secondview.xib文件,如果用户将点击主屏幕按钮。我已经编写了一个通过以下代码加载Secondview的方法..
self.second=[[[SecondWindow alloc]initWithNibName:@" HarbourFront" bundle:nil]autorelease];
从MainWindow屏幕。
我的界面声明是,
#import "SecondWindow.h"
@interface TrainingProject_1AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
SecondWindow *second;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic,retain) SecondWindow *second;
-(IBAction) listTableView:(id) sender;
@end
// Definition in ".m" file
@synthesize second;
-(IBAction) listTableView:(id) sender {
NSLog(@"event called");
self.second=[[[SecondWindow alloc]initWithNibName:@" HarbourFront" bundle:nil]autorelease];
}
我检查过该方法被调用但是SecondWindow没有加载。
如何加载SecondWindow?
答案 0 :(得分:1)
试试这段代码:
self.second=[[[SecondWindow alloc]initWithNibName:@" HarbourFront" bundle:nil]autorelease];
[self .navigationController pushViewController:self.second animated:YES];
希望它可以帮助你......
答案 1 :(得分:0)
只需输入此行[self.window addSubView:self.second.view];在线下面self.second = [[[SecondWindow alloc] initWithNibName:@“HarbourFront”bundle:nil] autorelease];