簡體   English   中英

Typedef枚舉設置和訪問

[英]Typedef enum setting and accessing

我在MainView.h頭文件中的接口聲明之前有這個。

typedef enum { UNKNOWN, CLEAR, NIGHT_CLEAR, CLOUDY, NIGHT_CLOUDY } Weather;

然后我宣布它是這樣的:

Weather weather;

然后做了一個訪問者:

@property Weather weather;

並合成它。

我的問題是,如何在不崩潰的情況下在不同的類中使用它? 我已經為MainView導入了標題。 我試着像這樣使用它:

MainView* myView = (MainView*)self.view;

[myView setWeather: CLEAR];

它不會在Xcode中引發任何錯誤,但在代碼運行時它會崩潰,並說:

-[UIView setWeather:]: unrecognized selector sent to instance *blah*

我在這里做錯了嗎?

'天氣'是一種不是變量的類型。

所以,你想要這樣的東西:

Weather theWeather = [mainView weather];
if (theWeather == CLEAR)
{
<do something>
}

MainView有ivar的地方:

 Weather weather;

在C中,Weather將是類型定義,而不是變量。

查看Objective C中的typedef enum

你必須刪除*Weather* weather weather必須是整數,而不是指針。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM