Re: [問題] 呼叫其他.h檔元件問題

看板MacDev作者 (白毛)時間11年前 (2014/02/13 11:37), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《chk95 (真男人魂)》之銘言: : 主要是在b.m檔裡面呼叫a.h檔的原件做更新資料的動作 : 程式大致如下 : NewsController* newController = : [self.storyboard instantiateViewControllerWithIdentifier:@"NewsPages"]; : [self.navigationController pushViewController:newController animated:YES]; : newController.title = @"abcd"; : newController.newsPage_textView.text=@"oh ya"; 你用lldb設breakpoint在這一行看看 newsPage_textView一定是nil 因為這個時候newController裡的view還沒load進來 此時newController只有init而已 因為pushViewController後並非馬上顯示 而是等到runloop結束後 才會統一更新畫面 此時才會去access controller的view 其subview才會通通被load進來 你可以做個實驗 在newController.newsPage_textView.text=@"oh ya";之前 加上一行newController.view; 這樣就可以抓到newsPage_textView了 所以一般的做法 要等到viewDidLoad才抓得到news_textView 建議你把view controller的文件讀過一次 才會瞭解iOS的view是如何運作的 https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html 懶得讀的話直接看Figure4-1那張圖 : 在xcode尚未更新為5.02時,執行這個程式都可順利改寫title以及newsPage_textView : 的資料並秀出,但xcode更新後再次執行此專案才發現title順利改寫了 : 但newsPage_textView卻無法更新資料 : storyboard id也有做定義 : 在a.m檔執行newsPage_textView改寫資料也可以順利改寫 : 唯獨b.m呼叫它時要改寫卻不行,因之前xcode更新前執行專案都正常 : 所以小弟實在是不知道問題出在哪邊 : 是否有大大能解救一下愚昧的小弟呢?? : 實在是感激不盡 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.116.75 ※ 編輯: whitefur 來自: 118.160.116.75 (02/13 12:11)

02/13 12:23, , 1F
太感激大大的資訊了,看來基本功還是沒搞好,看來要專心k一
02/13 12:23, 1F

02/13 12:24, , 2F
下viewcontroller的運行流程,真的是太感激您了QQ
02/13 12:24, 2F
文章代碼(AID): #1I_3tqH2 (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1I_3tqH2 (MacDev)