2008-10-28 92 views
0

我有MainViewController調用WebViewController(從UICatalog示例應用程序) 在WebViewController中,我做了一些函數setValue(){...}設置一些值作爲參數傳遞給變量(NSString *值)從WebViewController .h但是當我嘗試從MainViewController東西像WebViewController targetViewController ... targetViewController.setValue(值),它說:「錯誤:請求成員'setValue'的東西不是結構或聯盟」...通過值之間的值

回答

1

如果你有一個名爲「value」的屬性,並使用@sythesize爲你創建一個方法,在這種情況下你使用「。」來調用。註釋:

targetViewController.value = whatever; 

或者你可以撥打二傳手徹底無論您或@synthesize編寫方法:

[targetViewController setValue:whatever]; 

的屬性語法(class.property =什麼)真的只是一個快捷方式調用一個「setValue:」方法,作爲回報,屬性的@property和@synthesize機制只是爲你寫了一段有用的代碼。

編輯:我以前說過,如果你只是寫了一個「setValue:」方法,你可以使用「class.value = newValue」符號來調用它,但這是不正確的 - 你必須定義一個@property來使用「 「。符號。

1

我相信

targetViewController.value = whatever; 

如果你已經擁有了@property只會工作,申報;如果不是,則需要使用完整的方法調用語法:

[targetViewController setValue: whatever]; 

否則,Kendall對於使用setters和@synthesize是正確的。

而且你的語法使用過程Ç

targetViewController.setValue(value); 

絕對將無法​​正常工作寫入。

+0

對我而言,你是完全正確的 - 在測試之後,你必須使用@property來使用class.value語法進行調用。我會編輯我的迴應,以免傳播錯誤的觀念...... – 2008-10-28 18:54:04

0

您還需要確保#import您的targetViewController.h文件。