【发布时间】:2016-03-25 19:03:41
【问题描述】:
如何使用 Objective-c 将 UIAlertController 警报操作按钮与操作处理程序链接起来?我正在使用 Xcode 7.1。
这是我的代码:
- (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];
}
【问题讨论】:
-
我已经读过了。但我想将按钮与操作联系起来。
-
这就是它的用途。 - actionWithTitle: style: handler: 你将这些动作添加到 UIAlertController。
标签: ios objective-c uialertcontroller