首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在SWIFT3 Xcode8.2中显示IOS应用程序中Snackbar操作的特定视图

如何在SWIFT3 Xcode8.2中显示IOS应用程序中Snackbar操作的特定视图
EN

Stack Overflow用户
提问于 2018-06-25 14:14:13
回答 1查看 815关注 0票数 0

如何从IOS中的Snackbar操作在我的SWift 3中的IOS应用程序上显示另一个视图?我尝试了以下代码(即,只要快捷栏出现,我点击快捷栏的操作部分,就会打开一个Id为PatientVCPatientViewController新视图):

代码语言:javascript
复制
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是我想要display.But的成员的名称,这会给我一个错误,EncounterFilterTableViewCell没有成员navigationController。一旦我在我的代码中继承了UIViewControllerUITableViewCell。从类UITableViewCellUIviewController继承多个类是错误的。应该做些什么才能显示由ID为PatientVCPatientViewController表示的视图。下面是我的类的完整代码,其中包含Snackbar代码。

代码语言:javascript
复制
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)

    }

}
EN

回答 1

Stack Overflow用户

发布于 2018-06-25 17:27:14

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

代码语言:javascript
复制
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中,像这样初始化单元格-

代码语言:javascript
复制
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!;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51017266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档