UIAlertController崩溃错误

时间:2018-07-14 10:22:40

标签: swift swift4 uialertcontroller

这是我的代码

exports.up = function(knex, Promise) {

    return createNeedSchema()
        .then(createNeed);

    function createNeedSchema(){
        return knex.schema.raw('CREATE SCHEMA need');
    }

    function createNeed(){
        return knex.schema
            .withSchema('need')
            .createTable('need', (table) => {

     table.foreign('id','user_id').references('id').inTable('member.user');
                table.foreign('id','project_id').references('id').inTable('project.project');
                table.timestamps();
            });
    }
});

运行此命令时,actionSheet刚出现在导航控制器的正上方,很小,有人知道解决方法吗?

1 个答案:

答案 0 :(得分:0)

在iPad上,警报将使用UIPopoverPresentationController显示为弹出窗口,它要求您使用sourceView和sourceRect或barButtonItem为弹出窗口的显示定义锚点。

要支持iPad,请包含以下代码:

alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = self.myButton.frame
self.presentViewController(alertController, animated: true, completion: nil)

这是一个示例: 假设您有一个按钮,并且要在按钮下方显示警报控制器:

@IBOutlet weak var myBtn: UIButton!

let alertController = UIAlertController(title: "title :)", message:"message...", preferredStyle: .actionSheet)
let defaultAction = UIAlertAction(title: "cancel", style: .cancel, handler: nil)

let deleteAction = UIAlertAction(title: "delete", style: .destructive) { (action: UIAlertAction) in
        //Do something
    }

let addAction = UIAlertAction(title: "...", style: .default) { (action) in
        //do something
    }

alertController.addAction(addAction)
alertController.addAction(deleteAction)
alertController.addAction(defaultAction)

alertController.popoverPresentationController?.sourceRect = self.myBtn.frame
alertController.popoverPresentationController?.sourceView = self.view
self.present(alertController, animated: true, completion: nil)

如果用户在UITableView内的单元格上进行选择后要显示操作表。您可以使用以下代码:

alertController.popoverPresentationController.sourceView = cell
alertController.popoverPresentationController.sourceRect = cell.bounds