2010-08-23 55 views
0

可以說我有兩個視圖控制器,firstViewController和secondViewController。 firstViewController應該呈現secondViewController,我也想通過firstViewController從secondViewController訪問一堆方法和屬性。iphone sdk:如何連接兩個UIViewController?

我這樣做只需使用firstViewController的頭文件中的導入標記,我只需將secondViewController導入firstViewController。

但現在我也希望它的工作相反。我想通過secondViewController從firstViewController訪問一些方法或其他東西。當我還將firstViewController導入到secondViewController時,由於某種原因它不起作用。

這是爲什麼?有沒有人知道解決這個問題?提前致謝!

+0

你問關於編譯問題(頭包括等),或關於面向對象的委派? – Santa 2010-08-23 09:40:16

+0

面向對象的代表團! – 2010-08-23 10:14:45

回答

0

解決方案很簡單。把這一行放在你的頭文件下面的導入,但在secondViewController聲明

#import "something" 

@class firstViewController; 

@interface secondViewController : UIViewController { 
firstViewController *firstVC; 
} 
+0

我也「導入」firstViewController或者我只是添加@class標籤? – 2010-08-23 10:07:16

+0

其中一個你必須導入,另一個你必須@class。問題是Xcode不知道如何解決的循環導入 – vodkhang 2010-08-23 10:59:01