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

相關問題