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];
}