0

我想检查位置服务已启用或禁用我的应用程序。因此,如果位置服务被禁用,我会发出不同的看法。我怎样才能使用一个故事板来做到这一点?我需要一个示例代码。如何查看位置服务并启动不同的视图?

My Storyboard

Segue公司标识(例如GPS视图的):

segue identifier

我的代码:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    if([CLLocationManager locationServicesEnabled]){ 

     NSLog(@"Konum Servisleri Açık"); 

     if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){ 
      alert = [[UIAlertView alloc] initWithTitle:@"Konum Servisleri Kapalı" message:@"Etkinleştirmek için ayarlardan konum servislerini kullanmasına izin verin." delegate:nil cancelButtonTitle:@"Tamam" otherButtonTitles:nil]; 
      [alert show]; 
      segueKontrol = @"Normal"; 
      [self performSegueWithIdentifier:@"Normal" sender:self]; 
     } 
     else{ 
      segueKontrol = @"GPS"; 
      [self performSegueWithIdentifier:@"GPS" sender:self]; 
     } 
    } 

    else{ 
     NSLog(@"Konum Servisleri Kapalı"); 
     alert = [[UIAlertView alloc] initWithTitle:@"Konum Servisleri Kapalı" message:@"Etkinleştirmek için ayarlardan Konum Servislerini etkinleştirin." delegate:nil cancelButtonTitle:@"Tamam" otherButtonTitles:nil]; 
     [alert show]; 

     segueKontrol = @"Normal"; 
     [self performSegueWithIdentifier:@"Normal" sender:self]; 
    } 

    // Do any additional setup after loading the view, typically from a nib. 
} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 

    if ([[segue identifier] isEqualToString:@"Normal"]) 
    { 
     CCHop2ViewController *cc = [segue destinationViewController]; 
    } 
    else{ 
    CCHopViewController *cc = [segue destinationViewController]; 
    } 

} 

回答

2

首先,在故事板名称的2个塞格斯唯一的名字,说AB 在您的第一个观点cont滚筒(处理最左边的视图),这样做:

if (([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) && 
      [CLLocationManager locationServicesEnabled]) { 
    [self performSegueWithIdentifier:@"A" sender:self]; 
} else { 
    [self performSegueWithIdentifier:@"B" sender:self]; 
} 
+0

它不起作用,什么也没有发生。查看无法启动。 – 2013-03-14 09:44:48

+0

确保您在故事板中正确命名您的segues。 – Rikkles 2013-03-14 09:56:55

+0

我编辑了我的问题。 – 2013-03-15 08:20:08