Swift 为什么UIActionSheet的cancleButton成为iOS7设备上的第一个按钮
我在iPhone5s iOS7上运行了我的应用程序。按钮索引错误,cancleButton成为第一个按钮。我很困惑,当我点击背景时,它会打开相册。我不知道为什么。真奇怪 这是我的密码Swift 为什么UIActionSheet的cancleButton成为iOS7设备上的第一个按钮,swift,ios7,uiactionsheet,Swift,Ios7,Uiactionsheet,我在iPhone5s iOS7上运行了我的应用程序。按钮索引错误,cancleButton成为第一个按钮。我很困惑,当我点击背景时,它会打开相册。我不知道为什么。真奇怪 这是我的密码 func actionsheetInIOS8Early() { let actionSheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "cancle", destructiveButtonTitle: nil)
func actionsheetInIOS8Early() {
let actionSheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "cancle", destructiveButtonTitle: nil)
actionSheet.addButtonWithTitle("album")
if UIImagePickerController.isSourceTypeAvailable( UIImagePickerControllerSourceType.Camera) {
actionSheet.addButtonWithTitle("camera")
}
actionSheet.showInView(self.view)
}
当你添加
let actionSheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "cancle", destructiveButtonTitle: nil)
这一行将把“取消”按钮添加到索引0中,然后再添加按钮
actionSheet.addButtonWithTitle("album")
if UIImagePickerController.isSourceTypeAvailable( UIImagePickerControllerSourceType.Camera) {
actionSheet.addButtonWithTitle("camera")
}
索引1处的相册按钮和索引2处的相机
所以,若你们想在最后一个索引中取消按钮,那个么你们需要添加
actionSheet.addButtonWithTitle("Cancel")
添加相册和相机按钮后。试试这个
let optionMenu = UIAlertController(title: "Title", message: "message", preferredStyle: .ActionSheet);
if UIImagePickerController.isSourceTypeAvailable( UIImagePickerControllerSourceType.Camera){
let cameraAction = UIAlertAction(title: "Camera", style: .Default, handler: {
(alert: UIAlertAction) -> Void in
// do something
})
optionMenu.addAction(cameraAction);
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
(alert: UIAlertAction) -> Void in
print("Cancelled")
})
optionMenu.addAction(cancelAction);
self.presentViewController(optionMenu, animated: true, completion: nil);
如果您如上所述添加cancel按钮,cancel按钮将显示在AlertController的末尾如果是,cancelButton确实是第三个按钮,但其中三个按钮靠得很近,cancelButton应该与前两个按钮分开,cancelButton位于底部如果您在第二行和第三行之间写入一些代码,当点击取消按钮时,你可以做一些事情此代码用于iOS7的自适应:如果它不起作用,请告诉我,我可以找出此代码的错误。你的代码在iOS8及更高版本上没有问题,但在iOS7上无法使用。这是一种非常好的u。我找到了答案,因为在动作表的按钮数组中,第一个元素是Cancel button。之后添加了其他按钮。所以当它加载时,“取消”按钮位于顶部,就像它位于索引0上一样。