我这样做通知:我用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];
}在预测类中:
[[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.
}它不起作用。我做错什么了?
发布于 2013-02-15 21:48:58
如果你想在weatherViewController中调用通知,你需要定义这个类的viewDidLoad方法。
确保您调用的是此viewController的viewDidLoad。
https://stackoverflow.com/questions/14895392
复制相似问题