导航控制器UINavigationController
2013-09-08 22:58
453 查看
AppDelegate.h
#import <UIKit/UIKit.h>
@class ViewController;
@class ViewController1;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) ViewController1 *viewController1;
@property (strong, nonatomic) UINavigationController *myNav;
@end
AppDelegate.m
主类
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
}
-(id)initWithAppDelegate:(id)delegate;
@end
m:
#import "ViewController.h"
#import "AppDelegate.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(id)initWithAppDelegate:(id)delegate
{
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"go" style:UIBarButtonItemStylePlain target:delegate action:@selector(go)];
self.navigationItem.rightBarButtonItem = myButton;
self.title = @"主界面";
return self;
}
-(void)loadView
{
UITextView *myText = [[UITextView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myText.text = @"主界面";
self.view = myText;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
ViewController1.m
#import "ViewController1.h"
#import "AppDelegate.h"
@interface ViewController1 ()
@end
@implementation ViewController1
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(id)initWithAppDelegate:(id)delegate
{
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:delegate action:@selector(back)];
self.navigationItem.leftBarButtonItem = myButton;
self.title = @"子界面1";
return self;
}
-(void)loadView
{
UITextView *myText = [[UITextView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myText.text = @"子界面1";
self.view = myText;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#import <UIKit/UIKit.h>
@class ViewController;
@class ViewController1;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) ViewController1 *viewController1;
@property (strong, nonatomic) UINavigationController *myNav;
@end
AppDelegate.m
#import "AppDelegate.h" #import "ViewController.h" #import "ViewController1.h" @implementation AppDelegate @synthesize myNav; @synthesize viewController1; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithAppDelegate:self]; //self.window.rootViewController = self.viewController; viewController1 = [[ViewController1 alloc] initWithAppDelegate:self]; self.myNav = [[UINavigationController alloc] initWithRootViewController:self.viewController]; [self.window addSubview:myNav.view]; [self.window makeKeyAndVisible]; return YES; } -(void)go { [myNav pushViewController:viewController1 animated:YES]; } -(void)back { [myNav popViewControllerAnimated:YES]; }
主类
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
}
-(id)initWithAppDelegate:(id)delegate;
@end
m:
#import "ViewController.h"
#import "AppDelegate.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(id)initWithAppDelegate:(id)delegate
{
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"go" style:UIBarButtonItemStylePlain target:delegate action:@selector(go)];
self.navigationItem.rightBarButtonItem = myButton;
self.title = @"主界面";
return self;
}
-(void)loadView
{
UITextView *myText = [[UITextView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myText.text = @"主界面";
self.view = myText;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
ViewController1.m
#import "ViewController1.h"
#import "AppDelegate.h"
@interface ViewController1 ()
@end
@implementation ViewController1
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(id)initWithAppDelegate:(id)delegate
{
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:delegate action:@selector(back)];
self.navigationItem.leftBarButtonItem = myButton;
self.title = @"子界面1";
return self;
}
-(void)loadView
{
UITextView *myText = [[UITextView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myText.text = @"子界面1";
self.view = myText;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
相关文章推荐
- IOS UINavigationController 导航控制器
- UI:导航控制器UINavigationController的使用
- iOS开发UINavigation系列四——导航控制器UINavigationController
- swift UINavigationController 导航控制器(六)【转自http://blog.csdn.net/zhang_biao_1991/article/details/313927】
- Snail—UI学习之导航视图控制器UINavigationController(系统)
- IOS第12天(2,UINavigationController导航控制器)
- 导航控制器UINavigationController
- 导航控制器UINavigationController
- Swift UINavigationController(导航控制器)的创建及导航栏的设置
- 学习iOS自定义导航控制器UINavigationController
- iOS开发UINavigation——导航控制器UINavigationController
- Xcode9学习笔记17 - 导航视图控制器UINavigationController
- Swift UINavigationController(导航控制器)的创建及导航栏的设置
- iOS开发UINavigation——导航控制器UINavigationController
- 【iOS开发-26】利用协议代理实现导航控制器UINavigationController视图之间的正向传值和反向传值
- Swift UINavigationController(导航控制器)的创建及导航栏的设置
- 导航控制器UINavigationController
- ios 导航控制器UInavigationController跳转以及返回传值
- UINavigationController/导航控制器
- 导航控制器UINavigationController和选项卡栏控制器UI...