如何在SWIFT3 XCODE 8.2中的IOS应用程序中的Snackbar的操作中显示特定视图

问题描述 投票:0回答:1

如何从IOS中Snackbar的操作在SWift 3中显示我的IOS应用程序上的另一个视图?我尝试了下面的代码(即一旦小吃栏出现,我点击Snackbar的动作部分,然后PatientViewController的新视图应该以Id为PatientVC打开):

override func setSelected(_ selected: Bool, animated: Bool) {

        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
        let message = MDCSnackbarMessage()

        let action = MDCSnackbarMessageAction()
        let actionhandler = {() in
           let actionmessage = MDCSnackbarMessage()
            actionmessage.text = "Button Click Success"
           MDCSnackbarManager.show(actionmessage)
            let storyboard = UIStoryboard(name: "Main", bundle: nil);
            let vc = storyboard.instantiateViewController(withIdentifier: "PatientVC") as! PatientViewController; 
            self.navigationController?.pushViewController(vc, animated: true);



        }
        action.handler = actionhandler
        action.title = "Done"
        message.action = action





        message.text = "Welcome"
        MDCSnackbarManager.show(message)

    }

其中PateintVC是id,PatientViewController是我要展示的viewController的名字。但是这给了我EncounterFilterTableViewCell没有成员navigationController的错误。一旦我在我的代码中与UIViewController一起使用UITableViewCell。它给出了来自UITableViewCellUIviewController类的多重遗嘱的错误。应该做什么,以便我可以用ID PatientViewController显示我的PatientVC代表的视图。下面是我班级的完整代码,其中包含我的Snackbar代码。

import UIKit

import MaterialComponents.MaterialSnackbar

class EncounterFilterTableViewCell: UITableViewCell{

    @IBOutlet weak var filterCheckBox: CheckBox!
    @IBOutlet weak var filterNameTextView: UITextView!

    var filterIndex : [String : Int] = [
        getDataFromAppLanguage("Final") + " " + getDataFromAppLanguage("Diagnosis") : 0,
        getDataFromAppLanguage("Diagnosis") : 1,
        getDataFromAppLanguage("Test") : 2,
        getDataFromAppLanguage("Operation") : 3,
        getDataFromAppLanguage("Drug") : 4,
        getDataFromAppLanguage("Media") : 5,
        getDataFromAppLanguage("FormsEn") : 6,
        getDataFromAppLanguage("PatientEn") + " " + getDataFromAppLanguage("Status") : 7
    ]
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    @IBAction func filterBoxClicked(_ sender: AnyObject) {
        EncounterFilterViewController.updateFilterStatus(filterIndex[filterNameTextView.text]!)
    }


    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
        let message = MDCSnackbarMessage()

        let action = MDCSnackbarMessageAction()
        let actionhandler = {() in
           let actionmessage = MDCSnackbarMessage()
            actionmessage.text = "Button Click Success"
           MDCSnackbarManager.show(actionmessage)
             let storyboard = UIStoryboard(name: "Main", bundle: nil);
        let vc = storyboard.instantiateViewController(withIdentifier: "PatientVC") as! PatientViewController; 
        self.navigationController?.pushViewController(vc, animated: true);            
        }
        action.handler = actionhandler
        action.title = "Done"
        message.action = action





        message.text = "Welcome"
        MDCSnackbarManager.show(message)

    }

}
ios swift3 uiviewcontroller xcode8 snackbar
1个回答
0
投票

更改自定义单元格以使其正常工作 -

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)

    let componentFrame = CGRect(x: 20, y: 20, width: 40, height: 30)
    toggleSwitch.frame = componentFrame
    toggleSwitch.addTarget(self, action: #selector(SwitchTableViewCell.switchAction), for: .valueChanged)
    self.contentView.addSubview(toggleSwitch);
}

convenience init(style: UITableViewCellStyle, reuseIdentifier: String?, callingView : UIViewController) {

    self.init(style: style, reuseIdentifier: reuseIdentifier)
    callingViewController = callingView
}

override func setSelected(_ selected: Bool, animated: Bool) {
    let message = MDCSnackbarMessage()
    message.text = "The groundhog (Marmota monax) is also known as a woodchuck or whistlepig."

    let action = MDCSnackbarMessageAction()
    let actionHandler = {() in

        let storyBoard = UIStoryboard.init(name: "Main", bundle: nil)
        let vc = storyBoard.instantiateViewController(withIdentifier: "DetailView")
        self.callingViewController?.navigationController?.pushViewController(vc, animated: true)

    }
    action.handler = actionHandler
    action.title = "OK"
    message.action = action

    MDCSnackbarManager.show(message)
}

在ViewController中,像这样初始化单元格 -

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell : SwitchTableViewCell? = tableView.dequeueReusableCell(withIdentifier: "TestIdentifier") as? SwitchTableViewCell
    if(cell == nil)
    {
        cell = SwitchTableViewCell(style: .default, reuseIdentifier: "TestIdentifier", callingView : self)
    }

    cell?.toggleSwitch.isOn = myData1[indexPath.row];

    return cell!;
}
© www.soinside.com 2019 - 2024. All rights reserved.