0

私は次のような通知を行います:mainViewにコードがあります:

- (void)viewDidLoad
{

CGRect view1Hrame;
view1Hrame.origin.x = 160;
view1Hrame.origin.y = 215;
view1Hrame.size = self.currenWeatherView.frame.size;

weatherViewController *view1 = [[weatherViewController alloc] initWithForecast:[[Forecast alloc] initWithForecastInCurrentLocation]];    

[[NSNotificationCenter defaultCenter] addObserver:view1 selector:@selector(forecastChanged) name:@"forecastChanged" object:nil];

view1.view.backgroundColor = [UIColor colorWithRed:0 green:255 blue:0 alpha:0.06];

[currenWeatherView addSubview: view1.view];
}

Forecastクラス:

 [[NSNotificationCenter defaultCenter] postNotificationName:@"forecastChanged" object:nil];

WeatherViewControllerで

 - (void)viewDidLoad
  {
   [super viewDidLoad];

   [[NSNotificationCenter defaultCenter] addObserver:self       selector:@selector(forecastChanged) name:@"forecastChanged" object:nil];

    // Do any additional setup after loading the view from its nib.
   }

それは動作しません。私は何を間違えましたか?

4

1 に答える 1

0

で通知を呼び出す場合はweatherViewController、このクラスのviewDidLoadメソッドを定義する必要があります。

このviewControllerのviewDidLoadを呼び出していることを確認してください。

于 2013-02-15T13:48:58.110 に答える