代码之家  ›  专栏  ›  技术社区  ›  sudo rm -rf

Typedef枚举设置和访问

  •  3
  • sudo rm -rf  · 技术社区  · 14 年前

    在我的 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*
    

    我在这里做错什么了吗?

    3 回复  |  直到 14 年前
        1
  •  6
  •   westsider    14 年前

    “Weather”是一种类型,而不是变量。

    所以,你想要这样的东西:

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

    如果MainView有ivar:

     Weather weather;
    
        2
  •  1
  •   Rits    14 年前

    你必须移除 * Weather* weather . weather