所以我有我的主视图控制器,我只有一个里面的按钮。按钮的代码是:
- (IBAction)eventsButton:(id)sender {
self.eventsViewController =[[EventsViewController alloc]initWithNibName:@"EventsViewController" bundle:nil];
[self.navigationController pushViewController:eventsViewController animated:YES];}
其中 EventsViewController 是另一个控制器,当单击此按钮时我想在其中导航。但是当我点击它时,什么也没有发生。我没有导航到另一个控制器。
ViewController.h
-------------------
#import <UIKit/UIKit.h>
@class EventsViewController;
@interface ViewController : UIViewController <UIActionSheetDelegate>
- (IBAction)eventsButton:(id)sender;
@property (strong, nonatomic) EventsViewController *eventsViewController;
@end
ViewController.m
-----------------
#import "ViewController.h"
#import "EventsViewController.h"
@implementation ViewController
@synthesize eventsViewController;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)eventsButton:(id)sender {
self.eventsViewController =[[EventsViewController alloc]initWithNibName:@"EventsViewController" bundle:nil];
[self.navigationController pushViewController:eventsViewController animated:YES];
}
@end
我在 IBACTION 中放置了一个断点,我看到代码已执行,但它从未将我导航到另一个控制器。另一个控制器只是我用 Xcode 创建的一个简单控制器,它包含 Xcode 提供的所有代码,而没有我的。有任何想法吗?