2012-07-31 133 views
0

我有一個側面菜單的應用程序。啓動時在視圖控制器之間傳遞數據

我有2 ViewControllerRearViewControllerFrontViewController

RearViewController我有一個tableView,我希望一旦應用程序啓動FrontViewController加載該表中的第一個元素。

我曾嘗試加入

frontViewController.category = [rearViewController.fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]; 
AppDelegate

,但所有它得到的是一個零對象。 謝謝。

+0

它將在AppDelegate中成爲零,因爲它在AppDelegate中沒有任何價值......直到包含它們的方法被調用時,您的對象纔會有值! – 2012-07-31 13:01:26

+0

是的,我想過這個。 – Devfly 2012-07-31 13:08:32

+0

你想要什麼..... ???你想要變後退? 這怎麼可能? – TheTiger 2012-07-31 13:19:35

回答

0

不會從一個視圖控制器發送到另一個像這樣的數據....你必須推...使用pushViewController 在RearViewController寫...

[self.navigationController pushViewController:FirstViewController animated:YES]; 
+0

我不明白。我的根控制器是FrontViewController,我無法理解你的意思。 – Devfly 2012-07-31 12:40:21

+0

猜猜我第一次沒有找到你...... – IronManGill 2012-07-31 12:59:19

0

enter image description here

我在這種情況下使用協議。

@protocol CommonDataSource 
- (TheType *)dataSource; 
@end 


@interface AppDelegate : NSObject <UIAppDelegate, CommonDataSource> 
@end 

@implementation AppDelegate 
- (TheType *)dataSource 
{ 
    ... 
} 
@end 


@interface TheAViewController : UIViewController 
@property (...) id<CommonDataSource> commonDataSource; 
@end 

@interface TheBViewController : UIViewController 
@property (...) id<CommonDataSource> commonDataSource; 
@end 


- (IBAction)theActionA:(id)sender 
{ 
    TheAViewController *aaa = ...; 
    a.commonDataSource = (AppDelegate*)...; 
} 


- (IBAction)theActionB:(id)sender 
{ 
    TheAViewController *aaa = ...; 
    a.commonDataSource = (AppDelegate*)...; 
} 

祝你好運!

+0

這不適合我。我無法讓它顯示數據。 – Devfly 2012-07-31 14:20:57

相關問題