gpt4 book ai didi

swift - 有没有办法可以识别与 viewController 关联的 .storyboard?

转载 作者:行者123 更新时间:2023-11-30 10:35:39 26 4
gpt4 key购买 nike

storyboard中,可以找到关联的viewControllerid。但据我所知,反过来是不可能的:也就是说,在 viewController 中,我可以看到它连接到哪个 storyboard 吗?

事实是,我目前正在使用 viewController,但不知道它与什么 storyboard 关联。

以下是包含 Shreeram-Bhat 建议的代码:

import UIKit

protocol PickNumberVieDelegate: class {
func dismissPickNumberView(tempDef:String, tempAlter:String)
}

class PickNumberViewController: UIViewController,UITableViewDataSource, UITableViewDelegate{

weak var delegate: PickNumberVieDelegate?
var whatTypOfNumber = 0
@IBOutlet weak var tableview: UITableView!
@IBOutlet weak var indicator: UIActivityIndicatorView!

var arr = [PresentationNumberOption]()

var tempAlernatNr = ""
var tempDefaultNr = ""

override func viewDidLoad() {
super.viewDidLoad()

//HERE
var storyboard: UIStoryboard? { get }
print("🐥here", storyboard);

self.setUserInterfaceStyleLight()
if (whatTypOfNumber == 0) {

self.title = NSLocalizedString("TimeControlled AfterWork Time" , comment: "")

}else if (whatTypOfNumber == 1){
self.title = NSLocalizedString("TimeControlled Showing Number" , comment: "")
}else{

self.title = NSLocalizedString("Display Number", comment: "")
}

}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

var mobilNumber = ""
if let mobileNumberForThisDevice = CurrentPerson.shared().thisMobilePhone(){

mobilNumber = mobileNumberForThisDevice.address
};
Communication.sendGetCustomPresentationNumberOptionsforNumber(mobilNumber, withCallbackMethod: #selector(self.gotPresentationNumberOptions(_:)), callbackFailMethod: #selector(self.failedToGetNumber), on: self)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arr.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let CellIdentifier = "CellId"
var cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier)

if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: CellIdentifier)
}

var option: PresentationNumberOption?

option = arr[indexPath.row]
var str = option?.displayText()
str = str?.replacingOccurrences(of: "[", with: "")
str = str?.replacingOccurrences(of: "]", with: "")
cell?.textLabel?.text = str

if( whatTypOfNumber == 0){
if (ModelManager.shared()?.tcsm.defaultNr == option?.address) {

cell?.accessoryType = .checkmark

} else {
cell?.accessoryType = .none
}
}else{
if (ModelManager.shared()?.tcsm.alternateNr == option?.address) {

cell?.accessoryType = .checkmark
} else {
cell?.accessoryType = .none
}
}

return cell!
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

tempAlernatNr = (ModelManager.shared()?.tcsm.alternateNr)!
tempDefaultNr = (ModelManager.shared()?.tcsm.defaultNr)!

let presentationNumber: PresentationNumberOption?
presentationNumber = arr[indexPath.row]

if( whatTypOfNumber == 0){
if(presentationNumber?.address == ""){
if presentationNumber?.type == kPresentationNumberOptionTypeMobileNumber{

self.showVerificationScreen()
}else{

ModelManager.shared()?.tcsm.defaultNr = presentationNumber?.address ?? ""
delegate?.dismissPickNumberView(tempDef: tempDefaultNr, tempAlter: tempAlernatNr)
self.navigationController?.popViewController(animated: true)
}

}else{
ModelManager.shared()?.tcsm.defaultNr = presentationNumber?.address ?? ""
delegate?.dismissPickNumberView(tempDef: tempDefaultNr, tempAlter: tempAlernatNr)
self.navigationController?.popViewController(animated: true)
}
}else{
if(presentationNumber?.address == ""){
if presentationNumber?.type == kPresentationNumberOptionTypeMobileNumber{

self.showVerificationScreen()
}else{

ModelManager.shared()?.tcsm.alternateNr = presentationNumber?.address ?? ""
delegate?.dismissPickNumberView(tempDef: tempDefaultNr, tempAlter: tempAlernatNr)
self.navigationController?.popViewController(animated: true)
}

}else{
ModelManager.shared()?.tcsm.alternateNr = presentationNumber?.address ?? ""
delegate?.dismissPickNumberView(tempDef: tempDefaultNr, tempAlter: tempAlernatNr)
self.navigationController?.popViewController(animated: true)
}
}


}

@objc func gotPresentationNumberOptions(_ presentationNumbers: [Any]?) {
if let aNumbers = presentationNumbers {
self.arr = aNumbers as! [PresentationNumberOption]
}

indicator.stopAnimating()

tableview.reloadData()
}

@objc func failedToGetNumber() {
//ALog("Failed to get presentation number options:%@", error)
indicator.stopAnimating()
}

func numberOfSections(in tableView: UITableView) -> Int {
// Return the number of sections.
return 1
}

func showVerificationScreen() {
print("🐥Show Verification Screen");

let nextController = NumberVerificationViewController(nibName: "NumberVerificationViewController", bundle: Bundle.main)

navigationController?.pushViewController(nextController, animated: true)
}
}

最佳答案

您可以从“storyboard”属性中获取它。以下是属性(property)声明。

var storyboard: UIStoryboard? { get }

如果您从代码中实例化了 ViewController,则该值将为 nil。你明白了,

if let storyboard = self.storyboard {
if let name = storyboard.value(forKey: "name") as? String {
print(name)
}
}

关于swift - 有没有办法可以识别与 viewController 关联的 .storyboard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58097550/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com