在快速的待办应用中,有一个UITableViewController和一个普通的UIViewController。在名为“ AddToDoVC”的UIViewController中,有一个用于显示待办事项名称的文本框和一个标题标签(viewTitle)“添加待办事项”。现在,按下添加按钮,它将保存toDo并在“ ToDos” UITableViewController上显示名称。现在,我插入了一个名为“ editAction”的UITableViewRowAction。当在tableView上按下此编辑按钮时,它将转到“ AddToDoVC”,我希望viewController进行一些更改,以使其成为一种编辑模式,例如,标题“ Add ToDo”更改为“ Edit” ToDo”或名称textField会自动成为保存的toDo的名称(如果有帮助,我正在使用Realm Swift进行保存)。现在,我该怎么做?到目前为止,这是我所写的内容,但始终会出现错误“致命错误:在解开Optional值时意外发现nil”。

在“待办事项” UITableViewController中:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {

    //Edit
    let editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit") {(editAction, indexPath) -> Void in

        //Shows AddTaskVC when "Edit" is pressed
        let editTaskVC = self.storyboard?.instantiateViewControllerWithIdentifier("addTaskVC") as! AddTaskVC
        self.navigationController?.pushViewController(editTaskVC, animated: true)

        //Changing the viewTitle's text from "Add Task" to "Edit Task" as it is now in an "Edit" mode -> this doesn't do anything other than give me the error "fatal error: unexpectedly found nil while unwrapping an Optional value"
        editTaskVC.viewTitle.text = "Edit Task"

    }

    //Return edit action
    return [editAction]

}


如何实现这种编辑模式?先感谢您。

最佳答案

而不是直接将值设置为标签。在str中定义一个字符串AddToDoVC,并将该字符串值分配给Label中的viewDidLoad()

当前不会设置标签的值,因为未在视图控制器中绘制标签,并且您正在为其分配值。

关于ios - 如何创建在按下UITableViewRowAction时显示的editing-mode-viewController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39325118/

10-11 22:19
查看更多