创建一个导航条,代码如下:
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *aVC = [[ViewController alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:aVC];
self.window.rootViewController = navigation;
return YES;
}
页面的跳转,代码如下:
#import "ViewController.h"
#import "QViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor blueColor];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 100,self.view.frame.size.width-20, 50)];
[btn setTitle:@"详情" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor redColor]];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)btnClick:(id) sender {
QViewController *aVC = [[QViewController alloc] init];
[self.navigationController pushViewController:aVC animated:YES];
}