您的位置:首页 > 产品设计 > UI/UE

导航控制器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

#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.
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: