@objc func abcPressed() {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: AlphabetController.storyboardIdentifier) as! AlphabetController
controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)
}
}
When I pressed abcPressed, had an error "Storyboard (<UIStoryboard: 0x600002c51ec0>) doesn't contain a view controller with identifier 'AlphabetController"
How to identify AlphabetController by code?
Please help me! Thanks You
class AlphabetController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
var collectionView: UICollectionView!
let alphabet = ["A", "Ă", "Â", "B", "C", "D", "Đ", "E", "Ê", "G", "H", "I", "K", "M", "N", "O", "Ô", "Ơ", "P", "Q", "R", "S", "T", "U", "Ư", "V", "X", "Y"]
var audioPlayer: AVAudioPlayer?
override func viewDidLoad() {
super.viewDidLoad()
}
I tried
extension AlphabetController {
static var storyboardIdentifier: String {
return String(describing: self)
}
Set the Identifier in Storyboard:
Note that it can be any string - for example, one might use: "alphaVC" - it does not need to match the name of the View Controller class.