ios - 在 swift (IOS) 中将模式 TableView 中的值返回到主 TableView

标签 ios swift

我有一个带有 TableView 的主视图 Controller 。当在单元格上按下按钮时,将出现一个模式并允许用户选择多项选择。所以我提出了一个模态 Controller ,它又是一个 tableViewController,它在关闭时会给出一个字符串值。但是,一旦 modalView 被关闭并返回到我的主 tableView,tableView.reload() 在展开可选值时会显示 Nil。

代码:

// In modalTableViewController
//Protocol
protocol modalViewControllerDelegate {
func sendText( text: String)
}

//after all cell operations Done Button Action
@IBAction func doneBtnPressed(_ sender: Any) {

    mystr = selectedValues.joined(separator: ",")
    if(mystr != "")
    {
        let vc = viewController()
        delegate?.sendText(text: self.mystr)
    }
    self.dismiss(animated: true, completion: nil)
}
//In viewController
class ViewController : UIViewController,modalViewControllerDelegate{
 func sendText(text: String) {
    saveFormValue(mystr: text)
}
// .....
//SaveFunction
func saveFormValue(mystr:String){
self.tableView.reloadData() //HERE IAM GETTING ERROR (FOUND NIL)
//save operations goes here

}


.....
///
//Checking Cell type and calling function
if (cell.type == .multiSelect) {
    showCheckBox(data: ["One","Two","Three"])       
}
// Modal view function
func showCheckBox(data:[String])
{
    print("ShowCheckBox")
    checkBoxData = data //Assigning to a globalVariable
    self.performSegue(withIdentifier: "multiselectSegue", sender: self)
}

最佳答案

您是否将 mainVC 分配为模式的委托(delegate)?我相信这是您缺少的步骤(基于发布的代码)

如果是,您可能需要添加断点并检查 sendTextsaveFormValue 方法是否确实被调用。

关于ios - 在 swift (IOS) 中将模式 TableView 中的值返回到主 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52828480/

相关文章:

ios - SecurityApplicationGroupIdentifier 的应用组返回 nil

swift - 使用当前用户电子邮件设置值

ios - 在数组中查找距用户位置最近的经度和纬度

ios - 印象笔记SDK : Cannot upload a note into my Sandbox account

swift - Swift 中两个不同的随机生成数

swift - Swift 中的 "required"关键字是什么意思?

iphone - 阻止 UIImageView 返回其在 View 中的原始位置?

ios - Firebase - iOS SDK - 按子值过滤

ios - Facebook 登录 :terminating with uncaught exception of type NSException in ios swift

swift - 请告诉我如何正确使用 swift 的注释掉。