在iOS中使用通知中心和可访问性

时间:2013-12-17 09:00:32

标签: ios ios7 notifications nsnotificationcenter

我在viewDidLoad视图中的controller.m类中有这个:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];

self.reachability = [Reachability reachabilityWithHostname:@"www.google.com"];

[self.reachability startNotifier];

我还在我的视图controller.m中创建了更改通知:

- (void)reachabilityChanged:(NSNotification*)note
{
Reachability* r = [note object];
NetworkStatus ns = r.currentReachabilityStatus;

if (ns == NotReachable)
{
    NSString* msg = @"Network problems have rendered the iTunes store inaccessible; please try again later.";
    UIAlertView* av = [[UIAlertView alloc] initWithTitle:nil
                                                 message:msg
                                                delegate:self
                                       cancelButtonTitle:@"Ok"
                                       otherButtonTitles:nil];
    [av show];  }
}

这会是我的所有观点吗?因为我有一个导航控制器,它似乎影响我使用的起始视图和我推动的那个。它是否正确?如果它不是导航控制器怎么办?

0 个答案:

没有答案