UITableView

//創(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{

//重寫時(shí) 一定要寫super

//loadView方法 負(fù)責(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;

//半透明效果

//開啟效果時(shí) 屏幕左上角為坐標(biāo)原點(diǎn)

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

self.navigationController.navigationBar.translucent = YES;

//欄背景顏色

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

//欄顏色

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

//欄標(biāo)題

// ? ?self.title = @"這是一個(gè)標(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.獲取第二頁面對(duì)象

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: 在第二頁聲明一個(gè)屬性 用來保存數(shù)據(jù)

@property(nonatomic,copy)NSString *string;

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

twoVC.string = self.tf1.text;

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

self.tf2.text = self.string;

#warning 協(xié)議1: 聲明協(xié)議(定義一個(gè)帶參數(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è)置代理人的對(duì)象和push的對(duì)象是一個(gè) 在創(chuàng)建push對(duì)象之前 設(shè)置delegate.

twoVC.delegate = self;

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

[twoVC release];

}

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

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

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

self.tf1.text = string;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 網(wǎng)絡(luò)請(qǐng)求:http協(xié)議了解客戶端發(fā)送請(qǐng)求信息(GET)服務(wù)器根據(jù)網(wǎng)絡(luò)鏈接, 找到對(duì)應(yīng)的相應(yīng)方法, 去服務(wù)器的數(shù)據(jù)庫...
    Vinc閱讀 2,551評(píng)論 1 14
  • UITableView TableView中取消選中顏色變化,在didSelectRowAtIndexPath中寫...
    藍(lán)汐o閱讀 535評(píng)論 0 0
  • *7月8日上午 N:Block :跟一個(gè)函數(shù)塊差不多,會(huì)對(duì)里面所有的內(nèi)容的引用計(jì)數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,727評(píng)論 1 14
  • 我跟L大學(xué)四年,同一專業(yè),但不是同一班級(jí),并不怎么相熟。 臨近大學(xué)畢業(yè)的一天,他們班舉行了離別宴。他喝了一些酒,來...
    一只有仙氣的草莓閱讀 317評(píng)論 2 4
  • 說是有那么一天, 你的身體成了我極熟的地方, 那轉(zhuǎn)灣抹角,那小阜平岡; 一草一木我全知道清清楚楚, 雖在黑暗里我也...
    貓總Amoy閱讀 936評(píng)論 0 0

友情鏈接更多精彩內(nèi)容