objective-cを使用してUIAlertController警告アクションボタンとアクションハンドラをリンクするにはどうすればよいですか?私はXcode 7.1を使用しています。私はあなたがそれを意味だと思うUIAlertControllerのアクションをどのように処理するのですか?
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"text mssg" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
// Ok action example
}];
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"Other" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
// Other action
}];
[alert addAction:okAction];
[alert addAction:otherAction];
[self presentViewController:alert animated:YES completion:nil];
:
- (IBAction)selectbtn:(UIButton *)sender {
UIAlertController *alert=[ UIAlertController alertControllerWithTitle:@"NEW" message:@"button pressed" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cameraaction=[UIAlertAction actionWithTitle:@"From camera" style:UIAlertActionStyleDefault handler:nil ];
[alert addAction:cameraaction];
UIAlertAction *libraryaction=[UIAlertAction actionWithTitle:@"From photo library" style:UIAlertActionStyleDefault handler:nil ];
[alert addAction:libraryaction];
UIAlertAction *cancelaction=[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDestructive handler:nil];
[alert addAction:cancelaction];
[self presentViewController:alert animated:YES
completion:nil];
}
あなたはドキュメントを読む必要があります。 https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/#//apple_ref/doc/uid/TP40014538-CH1-SW4 – Dare
私は既にそれを読んでいます。しかし、私はアクションとボタンをリンクしたい。 – ghoshghosh
これがこれのためのものです。 - actionWithTitle:style:handler:これらのアクションをUIAlertControllerに追加します。 – Dare