我想在用戶位於特定位置時在我的應用中顯示警報視圖。另外,我只想呈現一次警報視圖。對於這一點,我 有下面的代碼:過渡到另一個ViewController時重置變量
if(!hasShownAlertview && GMSGeometryContainsLocation(userLocation.coordinate, testPath, YES)){
hasShownAlertview = YES;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" [email protected]"Body" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *yesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"YES", nil) style:UIAlertActionStyleDefault handler:
^(UIAlertAction *action){
}];
UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"NO", nil) style:UIAlertActionStyleDefault handler:
^(UIAlertAction *action){
}];
[alertController addAction:noAction];
[alertController addAction:yesAction];
[self presentViewController:alertController animated:YES completion:nil];
}
}
的問題是:如果我去其他的ViewController,而用戶仍然在該位置,警報視圖再次在該視圖控制器中。原因在於,在新的ViewController出現之前hasShownAlertview
被設置回NO,因此警報視圖再次顯示。
我怎麼能解決這個問題?
你如何聲明'hasShownAlertview'可以告訴你? – Shreyank
它在.h文件中聲明爲ivar –
使屬性強'hasShownAlertview'' – Shreyank