2013年1月13日 星期日

Navigation Controller實作(二)

延續前一篇 Navigation Controller實作(一)

要在Navigation Bar上加入title的顯示

修改如下

1.在AppViewController.m加上顯示程式碼

 - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
  
    [self setTitle:@"Main Page"];
  
}

- (IBAction)toPage2:(id)sender {
    SecondViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondId"];

    [svc setValue:@"Page2" forKey:@"transferString"];
   
    [self.navigationController pushViewController:svc animated:YES];
}

2. 在SecondViewController.h加上傳送用的字串變數。
#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController
{
    NSString *transferString;
}


@end


3. 在SecondViewController.m加上顯示title的程式碼
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    self.title=transferString;
   
}


4. 顯示結果