UIViewController

//創(chuàng)建vc

? ?RootViewController *rootVC = [[RootViewController alloc]init];

? ?//根視圖

? ?self.window.rootViewController = rootVC;

#pragma mark - 初始化

? ?-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

? ? ? ?self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

? ? ? ?if (self) {

? ? ? ? ? ?NSLog(@"初始化");

? ? ? ?}

? ? ? ?return self;

? ?}

#pragma mark - 加載視圖

? ?-(void)loadView{

? ? ? ?//重寫時 一定要寫super

? ? ? ?//loadView方法 負責(zé)創(chuàng)建self.view

? ? ? ?[super loadView];

? ? ? ?NSLog(@"加載視圖");

? ?}

#pragma mark - 視圖已經(jīng)加載

? ?- (void)viewDidLoad {

? ? ? ?[super viewDidLoad];

? ? ? ?NSLog(@"視圖已經(jīng)加載");

? ? ? ?// Do any additional setup after loading the view.

? ? ? ?self.view.backgroundColor = [UIColor lightGrayColor];

//UI導(dǎo)航控制器

? ? ? ?//創(chuàng)建VC

? ? ? ?ViewController *root = [[ViewController alloc] init];

? ? ? ?//導(dǎo)航控制器: 管理控制器的控制器

? ? ? ?//創(chuàng)建導(dǎo)航

? ? ? ?UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:root];

? ? ? ?//把導(dǎo)航設(shè)置為根視圖

? ? ? ?self.window.rootViewController = navi;

? ? ? ?//導(dǎo)航欄設(shè)置:controller(欄)/item(欄上的元素)

? ? ? ?//導(dǎo)航欄顯示/隱藏

? ? ? ?self.navigationController.navigationBarHidden = NO/YES;

? ? ? ?//欄樣式

? ? ? ?self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

? ? ? ?//半透明效果

? ? ? ?//開啟效果時 屏幕左上角為坐標(biāo)原點

? ? ? ?//關(guān)閉時 導(dǎo)航欄的左下角為坐標(biāo)原點

? ? ? ?self.navigationController.navigationBar.translucent = YES;

? ? ? ?//欄背景顏色

? ? ? ?self.navigationController.navigationBar.backgroundColor = [UIColor yellowColor];

? ? ? ?//欄顏色

? ? ? ?self.navigationController.navigationBar.barTintColor = [UIColor blackColor];

? ? ? ?//欄標(biāo)題

? ? ? ?// ? ?self.title = @"這是一個標(biāo)題 ";

? ? ? ?self.navigationItem.title = @"Back";

? ? ? ?//分段

? ? ? ?UISegmentedControl *seg = [[[UISegmentedControl alloc]initWithItems:@[@"消息",@"電話"]] autorelease];

? ? ? ?seg.frame = CGRectMake(0, 0, 100, 30);

? ? ? ?//欄標(biāo)題視圖

? ? ? ?self.navigationItem.titleView = seg;

? ? ? ?//欄左側(cè)按鈕

? ? ? ?self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(left:)] autorelease];

? ? ? ?//欄右按鈕

? ? ? ?//系統(tǒng)按鈕樣式

? ? ? ?UIBarButtonItem *b1 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(right1)] autorelease];

? ? ? ?//自定義按鈕圖片

? ? ? ?UIBarButtonItem *b2 = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gift.png"] style:UIBarButtonItemStylePlain target:self action:@selector(right2)] autorelease];

? ? ? ?self.navigationItem.rightBarButtonItems = @[b1,b2];

? ? ? ?//修改導(dǎo)航欄上內(nèi)容的顏色

? ? ? ?self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

? ?//跳轉(zhuǎn)頁面

? ? ? ?UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];

? ? ? ?btn.frame = CGRectMake(200, 200, 100, 100);

? ? ? ?btn.backgroundColor = [UIColor yellowColor];

? ? ? ?[self.view addSubview:btn];

? ? ? ?[btn addTarget:self action:@selector(goTwo) forControlEvents:UIControlEventTouchUpInside];

#pragma mark - 跳轉(zhuǎn)頁面

? ? ? ?-(void)goTwo{

? ? ? ? ? ?//1.獲取第二頁面對象

? ? ? ? ? ?TwoViewController *twoVC = [[TwoViewController alloc] init];

? ? ? ? ? ?//2.跳轉(zhuǎn)(由導(dǎo)航控制器 從當(dāng)前push到第二頁)

? ? ? ? ? ?[self.navigationController pushViewController:twoVC animated:YES];

? ? ? ? ? ?//3.內(nèi)存管理

? ? ? ? ? ?[twoVC release];

? ? ? ?}

//UI頁面間傳值

#warning 屬性1: 在第二頁聲明一個屬性 用來保存數(shù)據(jù)

? ? ? ?@property(nonatomic,copy)NSString *string;

#warning 屬性2: 在push頁面之前傳值(創(chuàng)建對象之后 push之前)

? ? ? ?twoVC.string = self.tf1.text;

#warning 屬性3: 通過屬性給當(dāng)前頁內(nèi)容賦值

? ? ? ?self.tf2.text = self.string;

#warning 協(xié)議1: 聲明協(xié)議(定義一個帶參數(shù)的方法)

? ? ? ?@protocol PassDelegate

#warning 協(xié)議2: 定義代理人屬性

@property(nonatomic,assign)iddelegate;

#warning 協(xié)議3: 返回上一頁之前 讓代理人調(diào)用協(xié)議方法

[self.delegate passValue:self.tf2.text];

[self.navigationController popViewControllerAnimated:YES];

#warning 協(xié)議4: 簽協(xié)議

@interface RootViewController ()

#warning 協(xié)議5: 設(shè)置代理人

//為了保證設(shè)置代理人的對象和push的對象是一個 在創(chuàng)建push對象之前 設(shè)置delegate.

twoVC.delegate = self;

[self.navigationController pushViewController:twoVC animated:YES];

[twoVC release];

}

#warning 協(xié)議6: 實現(xiàn)協(xié)議方法

-(void)passValue:(NSString *)string{

//把收到的string 賦值給輸入框

self.tf1.text = string;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末猬仁,一起剝皮案震驚了整個濱河市扫尖,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌啡捶,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,204評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件柿究,死亡現(xiàn)場離奇詭異诉字,居然都是意外死亡,警方通過查閱死者的電腦和手機累舷,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評論 3 395
  • 文/潘曉璐 我一進店門浩考,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人被盈,你說我怎么就攤上這事析孽。” “怎么了只怎?”我有些...
    開封第一講書人閱讀 164,548評論 0 354
  • 文/不壞的土叔 我叫張陵袜瞬,是天一觀的道長。 經(jīng)常有香客問我尝盼,道長吞滞,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,657評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮裁赠,結(jié)果婚禮上殿漠,老公的妹妹穿的比我還像新娘。我一直安慰自己佩捞,他們只是感情好绞幌,可當(dāng)我...
    茶點故事閱讀 67,689評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著一忱,像睡著了一般莲蜘。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上帘营,一...
    開封第一講書人閱讀 51,554評論 1 305
  • 那天票渠,我揣著相機與錄音,去河邊找鬼芬迄。 笑死问顷,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的禀梳。 我是一名探鬼主播杜窄,決...
    沈念sama閱讀 40,302評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼算途!你這毒婦竟也來了塞耕?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,216評論 0 276
  • 序言:老撾萬榮一對情侶失蹤嘴瓤,失蹤者是張志新(化名)和其女友劉穎扫外,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體纱注,經(jīng)...
    沈念sama閱讀 45,661評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡畏浆,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,851評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了狞贱。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片刻获。...
    茶點故事閱讀 39,977評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖瞎嬉,靈堂內(nèi)的尸體忽然破棺而出蝎毡,到底是詐尸還是另有隱情,我是刑警寧澤氧枣,帶...
    沈念sama閱讀 35,697評論 5 347
  • 正文 年R本政府宣布沐兵,位于F島的核電站,受9級特大地震影響便监,放射性物質(zhì)發(fā)生泄漏扎谎。R本人自食惡果不足惜碳想,卻給世界環(huán)境...
    茶點故事閱讀 41,306評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望毁靶。 院中可真熱鬧胧奔,春花似錦、人聲如沸预吆。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,898評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽拐叉。三九已至岩遗,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間凤瘦,已是汗流浹背宿礁。 一陣腳步聲響...
    開封第一講書人閱讀 33,019評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留蔬芥,地道東北人窘拯。 一個月前我還...
    沈念sama閱讀 48,138評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親克蚂。 傳聞我的和親對象是個殘疾皇子寻定,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,927評論 2 355

推薦閱讀更多精彩內(nèi)容