1. 创建一个新的viewcontroller,比如 NewOrderViewController,同时创建实现文件和头文件
2. 创建一个view,比如 NewOrderView.xib
3. 双击打开NewOrderView.xib,指定其class为 NewOrderViewController,并在 Interface Builder中将view与File Owner连接起来
4. 在RootViewController.h文件中定义 NewOrderViewController, 设置其为属性,代码如下:
@class NewOrderViewController;
@interface RootViewController : UITableViewController {
NewOrderViewController *newOrderViewController;
}
@property (nonatomic, retain) NewOrderViewController *newOrderViewController;
5. 在RootViewController.m文件中实现跳转,代码如下:
//添加按钮
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"订单列表";
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
UIBarButtonItem *buttonEdit = [[[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStyleBordered target:self action:@selector(editCharacters)] autorelease];
UIBarButtonItem *buttonAdd = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showNewOrderView)] autorelease];
self.navigationItem.leftBarButtonItem=buttonEdit;
self.navigationItem.rightBarButtonItem=buttonAdd;
}
//实现跳转
- (void) showNewOrderView {
if (self.newOrderViewController == nil) {
NewOrderViewController *newOrder = [[NewOrderViewController alloc] initWithNibName:@"NewOrderView" bundle:nil];
self.newOrderViewController = newOrder;
[newOrder release];
}
[self.navigationController pushViewController:self.newOrderViewController animated:YES];
}