UIAlertAction的处理程序不起作用

明安

我是新手,现在正在学习一本教程书。这本书有点过时了,我有这个错误。

基本上,我试图进行表格单元格的选择,选择单元格后,它应该会弹出一个菜单,然后可以点击通话按钮。但是,在我按下调用按钮之后,现在没有出现预期的更改框,并且编译器给了我错误:不允许在取消分配时尝试加载视图控制器的视图,这可能导致未定义行为

编辑代码时没有错误,只是无法正常运行。

另一个问题是我的桌子上大约有17行,刺激器的屏幕上仅显示7行,而我无法向下滚动以查看其余的行。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath){

    //this creates an option menu when you tap on the row
    let optionMenu = UIAlertController(title: nil, message: "What do you want to do?", preferredStyle: .ActionSheet)
    //this is what happened after you hit the cancel option
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    //defines the action after tap on the call option
    let nocallAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
    let callActionHandler = {(action:UIAlertAction!)-> Void in
        let alertMessage = UIAlertController(title: "Service Unavaliable", message: "Sorry, the call is not avaliable yet, please retry later.", preferredStyle: .Alert)
        alertMessage.addAction(nocallAction)
    }
    //this is what happened after you hit the call option
    let callAction = UIAlertAction(title: "Call " + "123-000-\(indexPath.row)", style:
        UIAlertActionStyle.Default, handler: callActionHandler)
    //this is what happened after you hit the been there option
    let isVisitedAction = UIAlertAction(title: "I've been here", style: .Default, handler: {
        (action:UIAlertAction!) -> Void in
        let cell = tableView.cellForRowAtIndexPath(indexPath)
        cell?.accessoryType = .Checkmark
        })
    //add the action to the option menu
    optionMenu.addAction(isVisitedAction)
    optionMenu.addAction(callAction)
    optionMenu.addAction(cancelAction)

    self.presentViewController(optionMenu, animated: true, completion: nil)

}
旁听者

您永远不会在callActionHandler中显示视图控制器-它应如下所示:

let callActionHandler = {(action:UIAlertAction!)-> Void in
    let alertMessage = UIAlertController(title: "Service Unavaliable", message: "Sorry, the call is not avaliable yet, please retry later.", preferredStyle: .Alert)
    alertMessage.addAction(nocallAction)

    self.presentViewController(alertMessage, animated: true, completion: nil)
}

Swift还允许您与UIAlertAction同时创建完成处理程序,我认为它更具可读性:

    let callAction = UIAlertAction(title: "Call " + "123-000-243534", style: UIAlertActionStyle.Default) 
    { action in
        let alertMessage = UIAlertController(title: "Service Unavaliable", message: "Sorry, the call is not avaliable yet, please retry later.", preferredStyle: .Alert)
        alertMessage.addAction(nocallAction)

        self.presentViewController(alertMessage, animated: true, completion: nil)
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

OnChange事件处理程序不起作用

来自分类Dev

Opencart事件处理程序不起作用

来自分类Dev

SIGALRM的处理程序不起作用

来自分类Dev

Javascript事件处理程序不起作用

来自分类Dev

.ashx处理程序不起作用

来自分类Dev

JavaScript事件处理程序不起作用

来自分类Dev

陷阱处理程序不起作用?

来自分类Dev

SIGALRM的处理程序不起作用

来自分类Dev

Opencart事件处理程序不起作用

来自分类Dev

onclick事件处理程序不起作用

来自分类Dev

处理程序声明不起作用

来自分类Dev

类更改后,单击事件处理程序不起作用

来自分类Dev

具有UnhandledExceptionEventEventArgs的全局异常处理程序不起作用

来自分类Dev

点击处理程序在模板扩展指令中不起作用

来自分类Dev

Webgrid中的单击事件处理程序不起作用

来自分类Dev

自定义虚拟绑定处理程序不起作用

来自分类Dev

声明多个事件处理程序不起作用

来自分类Dev

Bootstrap Switch事件处理程序不起作用

来自分类Dev

HTTP处理程序在MVC IIS 8.0中不起作用

来自分类Dev

锁定多处理程序包不起作用

来自分类Dev

jQuery表单验证提交处理程序不起作用

来自分类Dev

C#关闭事件处理程序不起作用

来自分类Dev

Python GTK信号处理程序不起作用

来自分类Dev

Android处理程序删除发送消息不起作用

来自分类Dev

iOS HTTP发布重定向处理程序不起作用

来自分类Dev

Firebase $ save在事件处理程序函数中不起作用

来自分类Dev

React Form组件onSubmit处理程序不起作用

来自分类Dev

处理js在Chrome扩展程序中不起作用

来自分类Dev

为什么我的信号处理程序不起作用?