【发布时间】:2014-06-09 01:20:39
【问题描述】:
我正在尝试从位置管理器对象向我的 viewController 发出通知。它不起作用 - addObserver 方法中的选择器没有被调用。
Location Manager Object.m 文件(带有标准调度一次和初始化方法的单例)
- (void)setCurrentLocation:(CLLocation *)currentLocation
{
if (!_location) {
_location = [[CLLocation alloc] init];
}
_location = currentLocation;
NSNumber *latitude = [NSNumber numberWithDouble:self.location.coordinate.latitude];
NSNumber *longitude = [NSNumber numberWithDouble:self.location.coordinate.longitude];
NSLog(@"lat %@ & long %@ in notification section", latitude, longitude);
NSNotification *notification = [NSNotification notificationWithName:@"myNotification" object:self userInfo: @{kSetLat: latitude,
kSetLong: longitude}];
[[NSNotificationCenter defaultCenter] postNotification:notification];
}
ViewController.m(花园品种)
- (IBAction)welcomeNotification:(UIButton *)sender {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(sendGetRequest:) name:@"myNotification" object:[LPLocationManager sharedManager]];
[center removeObserver:self];
NSLog(@"welcomeNotication triggered");
}
【问题讨论】:
标签: ios nsnotification