我有一个名为 diffView 的基于导航的应用程序,我想在其中单击按钮打开新视图。为此,我们创建了一个视图,名为 file-new file-cocoa touch class-UIViewControllerSubclass,名为 next1。
在 diffViewAppDelegate.h 我写为
IBOutlet UIButton *btn1;
@property (nonatomic,retain) UIButton *btn1;
-(IBAction)buttonPressed:(id)sender;
并在 diffViewAppDelegate.m-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect bounds=window.bounds;
UIView* view=[[UIView alloc]initWithFrame:bounds];
[view setBackgroundColor:[UIColor redColor]];
[window addSubview:view];
CGRect buttonFrame= CGRectMake(80, 240, 200, 30);
btn1=[[UIButton alloc] initWithFrame:buttonFrame];
[btn1 setTitle:@"space" forState:UIControlStateNormal];
[btn1.titleLabel setFont:[UIFont fontWithName:@"Verdana" size:20]];
[btn1 addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
[view addSubview:btn1];
[self.window makeKeyAndVisible];
return YES;
}
-(IBAction)buttonPressed:(id)sender
{
next1 * nxt=[[next1 alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:nxt animated:YES];
[nxt release];
}
我没有收到任何错误,但是当我单击按钮时没有任何反应。
请建议我任何解决方案。