사용자가 버튼을 클릭하면 두 가지 옵션 중 하나를 선택하도록 요청하는 작업 시트가 표시됩니다. 옵션을 선택하고 나면 AlertView에서 응용 프로그램을 종료하고 작업 취소 또는 다른 응용 프로그램으로 계속 진행하도록 선택할 수 있습니다. 다음과 같이UIActionSheet 버튼을 누른 후 UIAlertView 표시
코드는 다음과 같습니다
.H
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface mapView : UIViewController <MKMapViewDelegate, UIActionSheetDelegate, UIAlertViewDelegate>
@property (nonatomic, weak)IBOutlet MKMapView *mapView;
@property (nonatomic, weak)IBOutlet UIBarButtonItem *getDirections;
- (IBAction)selectDestination:(id)sender;
- (void)checkLeave;
@end
하는 .m
- (IBAction)selectDestination:(id)sender
{
UIActionSheet *selectDestinationAS = [[UIActionSheet alloc] initWithTitle:@"Select Destination: " delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Destination 1", @"Destination 2", nil];
[selectDestinationAS showInView:self.view];
}
- (void)checkLeave
{
UIAlertView *checkLeaveAlert = [[UIAlertView alloc] initWithTitle:@"Leave CDSI?" message:@"This will open the Maps application to continue directions. Are you sure you want to continue?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Open", nil];
[checkLeaveAlert show];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self checkLeave];
if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString: @"Destination 1"]) {
NSURL *BOHMDirections = [NSURL URLWithString:@"http://maps.apple.com/?daddr=Destination1&saddr=Current+Location"];
[[UIApplication sharedApplication] openURL:BOHMDirections];
} else if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString: @"Destination 2"]) {
NSURL *BOPDirections = [NSURL URLWithString:@"http://maps.apple.com/?daddr=Destination2&saddr=Current+Location"];
[[UIApplication sharedApplication] openURL:BOPDirections];
}
}
ActionSheet이 옵션을 선택하면, 최대 보여주는지도 앱 (필요에 따라) 열리지 만 AlertView는 원래 응용 프로그램에 다시 들어가야 나타납니다. 앱을 종료하기 전에 어떻게 표시해야합니까?
에서가 아닌지도 앱은 어디 UIAlertView의 위임 방법? 경고보기에서 응답을 처리하지 않습니다. 앱이 종료되기 전에보기가 표시되면 취소를 누르면 아무 것도 수행되지 않습니다. – Tander