2012-11-23 55 views
2

我有一個應用程序,其中我使用sidemenu控制器,如Facebook應用程序。基本上是UITableViewController。當我在視圖中使用[self.tableView reloaddata]時,會出現第一次工作正常的方法。由於某些要求我需要從另一種觀點認爲controller.so我這樣做重新加載此表視圖:我的reloaddata調用不調用UItableviewcontroller中的委託方法?

SideMenuViewController *second = [[SideMenuViewController alloc]init]; 
[second viewWillappear:YES] 

我在哪裏重裝data.But當我這樣做的reloaddata不調用tableviewcontroller的cellforindexmethode但它調用numberOfRowsInSection方法可以幫助我找出錯誤的地方。

+0

您創建了SideMEnuViewController的新實例並調用viewWillAppear嗎? – Dave

+0

是的..我在做什麼 –

+0

@angry_developer:你是怎麼從SideMenuViewController顯示另一個視圖控制器的? –

回答

3

你可以使用一個通知到這一點。

在SideMenuViewController viewDidLoad方法你加本:

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(reloadTable) 
              name:@"SideMenuShouldRefreshDataNotification" 
              object:nil]; 

的reloadTable方法是這樣的:

-(void)reloadTable { 
dispatch_async(dispatch_get_main_queue(),^{ 
    [self.tableView reloadData]; 
}); 
} 

當你想刷新表,你剛剛從任何地方張貼此通知你想在您的應用程序。

[[NSNotificationCenter defaultCenter] postNotificationName:[NSNotification notificationWithName:@"SideMenuShouldRefreshDataNotification" object:nil]]; 
0

嘗試這樣的,這下面檢查:

[[self yourtableviewname] reloadData]; 
+0

閱讀這個問題它的tableviewcontroller.not一個iboutlet視圖 –

+0

在tableviewname中添加uitableviewcontroller對象名稱 – Vishal

0

如果你創建了一個新的實例,並調用一個方法就可以了,也不會引起你的舊的將被刷新。在您現有的TableView實例上調用refreshData,而不是創建新的實例。

0

使用協議委託重新加載。 另一個視圖控制器可能無法以您使用的方式調用viewWillAppear。 通過編寫一個委託來重新加載tableview,該委託會返回到其中包含tableview的控制器。

希望它有幫助。因爲在這裏你創建你的SideMenuViewController類的新實例

SideMenuViewController *second = [[SideMenuViewController alloc]init]; 
[second viewWillappear:YES] 

+0

這將是偉大的,如果你能給出詳細的答案 –

+0

試過呢? [鏈接](http://stackoverflow.com/questions/7130314/how-to-reload-tableview-of-another-uiviewcontroller-in-current-viewcontroller) – Vjlakshmi

+0

,我有一個tableviewcontroller,而不是與tableview的uiviewcontrollr –

0

此代碼永遠不會重新加載您的tableView。如果你調用reloadData它不會刷新前一個tableView實例。

並強制調用viewWillappear委託方法是一個壞習慣。

解決方案:

聲明的SideMenuViewController一個實例在你的viewController的@interface和該寫PROPERT。 當你去那個視圖設置SideViewController實例。 當用戶按下後退按鈕呼叫:

[sideViewControllerObject.tablView reloadData]; 
+0

我做到了,但沒有發生,我需要分配它? –

+0

沒有。你是否設置了該實例變量?我認爲這是零。 –

+0

的意思是?我添加了實例variuble和我做了eprocess.how來設置它?sidemenu = [[SideMenuViewController alloc] init]; –