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



如何在 SWift 3 的 IOS 应用程序上显示另一个视图,从 IOS 中的小吃栏操作?我尝试了以下代码(即一旦出现小吃栏并点击小吃栏的操作部分,就会打开一个新的视图PatientViewControllerId 作为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.一旦我与代码中的UITableViewCell一起UIViewController。它给出了来自类的多个固有UITableViewCellUIviewController的错误。 应该怎么做才能显示由 IDPatientVCPatientViewController表示的视图。下面是我班的完整代码,我有我的小吃吧代码。

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)
}
}

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

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)
}

在视图控制器中,像这样初始化单元格-

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!;
}

最新更新