2012-06-28 32 views
0

我想知道在某些數據加載之前視圖是否可以阻止自己打開爲模式視圖。防止視圖在數據加載之前作爲模態視圖打開

例如:

addTimeViewController = [[[AddTimeViewController alloc] initWithNibName:@"AddTimeViewController" bundle:nil] autorelease]; 
addTimeViewNavigationController = [[[UINavigationController alloc] initWithRootViewController:addTimeViewController] autorelease]; 

Item *item = (Item *)[_dataModel.items objectAtIndex:_currentEditCell];  
[self.navigationController presentModalViewController:addTimeViewNavigationController animated:YES]; 

[addTimeViewController updateTime:item]; 

這將打開AddTimeViewController爲模式,但AddTimeViewController具有真實顯示之前它加載某些數據。

會有一種方法來防止它在數據加載之前在模式視圖中打開自己嗎? 我想在AddTimeViewController本身內部執行此操作,我不想發送通知並以此方式執行此操作。

+0

其中來自的數據,並在加載時會如何你的應用程序知道嗎? –

+0

如何添加一些活動指標? – Guru

回答

1

你不應該阻止的viewController加載本身,而不是作爲視圖控制器打開,您可以添加,將告訴您當前正在從遠程源加載數據

+0

這就是我現在正在做的事情,但我不想在加載數據時顯示模式視圖,所以唯一的方法是發出通知然後將其作爲模態視圖打開? –

+0

是或將代表添加到新的視圖控制器,如果完成加載然後打開它,但你會做什麼,而不是打開視圖? –

+0

好吧,現在它顯示了一個模態視圖的加載屏幕,但我只想模態視圖出現,但我想我可以與代表一起工作,雖然 –

1

加載新ViewController用戶的一些中間的意見只當所有的數據任務完成時。

如果大量數據從服務器獲取,那麼你可以在後臺線程 -

Item *item = (Item *)[_dataModel.items objectAtIndex:_currentEditCell]; 
[self performSelectorOnMainThread:@selector(loadNewView) 
         withObject:item 
        waitUntilDone:YES]; 

-(void)loadNewView { 
    addTimeViewController = [[[AddTimeViewController alloc] initWithNibName:@"AddTimeViewController" bundle:nil] autorelease]; 
    addTimeViewNavigationController = [[[UINavigationController alloc] initWithRootViewController:addTimeViewController] autorelease]; 

    [self.navigationController presentModalViewController:addTimeViewNavigationController animated:YES]; 
} 
+0

會讓它更容易是的,我想我只是將它設置爲錯誤的方式,現在我的AddTimeViewController加載數據並處理它,我想我會使用上面建議的委託方式 –

相關問題