一、UINavigationController导航控制器,通过栈来完成全部页面的导航,UINavigationController有Navigation bar、Navigation View,Navigation toolbar组成。
1、下面演示通过UINavigationController完成IOS页面的导航,首先新建一个Empty工程,工程名称为MyNavigationControllerDemo,然后在添加一个类,名称为MainViewController,创建的时候勾选With XIB for user interface,然后打开AppDelegate.m页面在,将里面的代码修改如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
//刚才创建的主窗体,首页加载显示的内容
MainViewController *viewcontroller=[[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
viewcontroller.title=@"主页面";//标题的名称,在进入下一个页面时,返回的button上面显示的问题
UINavigationController *navcontroller=[[UINavigationController alloc] init];//创建UINavigationController
[navcontroller pushViewController:viewcontroller animated:YES];//将主页面push到栈里面
[self.window addSubview:navcontroller.view];//将navigationcontroller添加到主页面
[self.window makeKeyAndVisible];
[viewcontroller release];
return YES;
}
2、添加UIBarButtonItem,barButtonItem分为左右两个,我们现在将左右两个的barButtonItem添加上,在MainViewController.m的viewDidLoad里面分别添加如下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//使用系统自带的,也可以使用自定义的button,label等,后面我们会讲解自定义的Button,Label显示在上面
UIBarButtonItem *leftbtn=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(SaveBookMark:)];
self.navigati