2013年4月18日木曜日

プログラムからViewの移動

プログラム中からViewを移動(遷移)させたいとき

stroyboardを使ったviewへ移動するとき


#import "View1.h"

    View1 *vc1;
    vc1 = [self.storyboard instantiateViewControllerWithIdentifier:@"view1"];
    [self presentViewController:vc1 animated:YES completion:nil];


Identifier (@"view2")は、storyboardで、storyboard IDとして入力しておくこと。


xibファイルがあるとき

#import "View2.h"


    View2 *vc1 = [[View2 alloc]initWithNibName:@"View2" bundle:[NSBundle mainBundle]]  ;
    [self presentViewController:vc1 animated:YES completion:nil];


NIbNameは、xibファイル名


戻る場合


    [self dismissViewControllerAnimated:YES completion:nil];



Navigation Controllerを使っている場合

[[self navigationController] pushViewController:vc1 animated:YES];


1つ上の階層へ戻る
[self.navigationController popViewControllerAnimated:YES];


0 件のコメント:

コメントを投稿