0
我想在另一個方法(而不是viewDidLoad)中設置我的頁面標題。我的代碼如下。無法設置頁面標題的方法
基本上,'topicInfoLoader將從服務器檢索數據並將其作爲數組傳回給應用程序。我使用NSLOG來驗證主題的文本是否存在。但是,當我嘗試在此方法中設置頁面的標題時,它不起作用,即頁面不顯示標題。任何人都可以告訴我爲什麼會發生這種情況,我該如何解決這個問題?
- (void) getData
{
//Get info regarding the topic
NSString *topicInfoResourcePath = [NSString stringWithFormat:@"/topics/%@",self.topic._id];
Loader *topicInfoLoader = [[Loader alloc]initWithResourcePath:topicInfoResourcePath];
[topicInfoLoader setCompletionHandler:^(NSArray *anArray){
self.topicInfo = [anArray lastObject];
//NSLog shows that topic title value exists
NSLog(@"topic title :%@",self.topicInfo.text);
//Set the page title
self.title = self.topicInfo.text;
}];
實例方法'getData'屬於'self'。我正在調用另一個類的實例'topicInfo'的完成塊。在返回塊中,我可以執行各種操作,但似乎視圖控制器無法識別返回塊中其標題的設置。任何想法爲什麼? – Zhen
'topicInfo'是你的ViewController的一個屬性嗎?你能從該完成塊內的ViewController中訪問任何東西嗎?你爲什麼不在完成塊之外做'self.title'? – rjgonzo
因爲我需要的信息只能在完成塊中獲得。由於它是異步的,所以我不知道什麼時候可以得到它,因此將self.title放在外面可能無法正常工作。 – Zhen