UIViewController *viewCtrl=[[UIViewController alloc]init];
self.window.rootViewController=viewCtrl;
1.//創建視圖 self.view loadView self.view=nil會被調用
-(void)loadView
{
[super loadView];
}
- (void)viewDidLoad //self.view!=nil會被調用
首先是調用loadView 然後調用viewDidLoad
2.兩個ViewController之間的傳值問題 單例 KVO 通知 代理
(1)、單例的話 還是要藉助三方類 三方類是單例 防止被多次創建
static Content *content=nil; 全局變量不會被銷燬 有值的話就不會賦值
+(Content *)shareContent
{
//static Content *content=nil;
if(content==nil)
{
content=[[self alloc]init];
}
return content;
}
+(id)alloc
{
if(content==nil)
{
content=[self alloc];
}
return content;
}
(2)、通知 發送時有個userInfo 實質還是有三方類的幫助 兩個類之間沒有任何關聯
NSDictionary *dic=@{@"text":textFiled.text};
- (void)notificationAction:(NSNotification *)notification
{
NSString *text = [notification.userInfo objectForKey:@"text"];
_textLabel.text = text;
}
(3)、KVO 的話 還是利用全局變量的性質 -----給被觀察者設置爲全局變量 ---屬性的改變必須通過set、kvc方法
_contentV=[[ContentView alloc]init];
[_contentV addObserver:self forKeyPath:@"textFiledContent.text" options:NSKeyValueObservingOptionNew context:nil];
會發生的問題 監聽到得全局類 是空的 被觀察者的屬性是否存在
把文本屬性 初始化時就創建
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
_logLabel.text=[change objectForKey:@"new"];
}
(4)、代理方法 協議其實就是避免雙方拿錯
先拿到 轉到對方視圖前,就拿到對方的text 設置其相關屬性
(5)、創建真正意義的三方類
視圖切換時 以前的視圖並沒有被釋放掉、或銷燬 只是看不到
在其上面賦值、取值 不能直接先賦值給label,因爲其還沒創建
contentView.loginView=self;
_loginView.logLabel.text=_textFiledContent.text;
代理 替換掉loginView 並且有方法
代理實現代理協議 別人找代理,幫其實現功能
視圖創建
[self presentViewController:loginView animated:YES completion:nil];
視圖銷燬
[self dismissViewControllerAnimated:<#(BOOL)#> completion:<#^(void)completion#>]
視圖控制器
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
【ios 彙總 你可能不知道的調試技巧】
听着rap写代码
2020-02-20 22:14:16
textFiled要注意的地方
moon_shine
2020-06-24 18:40:42
AWS S3服務
阿飞小伙子_blogs
2020-06-04 13:28:05
UIScrollView頻道滑動(授人以魚,不如授人以漁)
hherima
2020-02-21 23:59:46
SDWebImage源碼解析
阿飞小伙子_blogs
2019-06-22 01:56:17
【精】iOS知識樹,知識點(包括對象、Block、消息轉發、GCD、運行時、runloop、動畫、Push、KVO、tableview,UIViewController、提交AppStore)
hherima
2018-09-04 22:03:01
IOS 開發,調用打電話,發短信,打開網址
moon_shine
2018-08-31 21:25:18
iOS系統架構和常用框架
陈荣科
2018-08-31 01:08:49
ios 內購服務器驗票(漏單處理)
听着rap写代码
2018-08-28 22:52:36
UIScrollView的基本用法
逝华_浮梦
2018-08-28 06:52:14