所以我刚刚做了一个关于添加模糊侧边栏菜单的教程。我复制了代码,但我似乎无法找到如何调用我在 Storyboard模式下制作的其他 ViewController。
我已经创建了文件并将它们链接到 UIViewControllers
。但是,当我尝试使用侧边栏菜单调用该 ViewController 时,出现黑屏。
这是我用来跟踪的文件的链接 http://goo.gl/ULWxJh 这是我跟随的 YouTube 视频的链接 http://www.youtube.com/watch?v=qaLiZgUK2T0
不知道为什么!任何帮助将不胜感激
class ViewController: UIViewController, SideBarDelegate {
var sideBar:SideBar = SideBar() // Side Bar
override func viewDidLoad() {
super.viewDidLoad()
// Side bar action and text
sideBar = SideBar(sourceView: self.view, menuItems: ["Home", "Business Directory", "Classifieds", "Featured News", "Jobs", "Restaurants", "Sports"])
sideBar.delegate = self
}
// Side Bar funcion
func sideBarDidSelectButtonAtIndex(index: Int) {
if index == 0{
let vc = ViewController()
self.presentViewController(vc, animated: true, completion: nil)
}else if index == 1{
let vc = businessDirectoryVC()
self.presentViewController(vc, animated: true, completion: nil)
}
}
}
最佳答案
将 Storyboard ID(在本例中为“ View ”)添加到主 Storyboard 中的 View Controller ,然后将以下内容添加到要从中调用侧边栏的文件中:
func sideBarDidSelectButtonAtIndex(index: Int) {
if index == 0 {
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let showView = storyBoard.instantiateViewControllerWithIdentifier("view") as! ViewController
self.presentViewController(showUebersicht, animated:true, completion:nil)
}
}
值“0”代表侧边栏中的第一项。将存储侧边栏项目的数组的值更改为另一个值。
关于xcode - 在 Swift 上向侧边栏菜单添加功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26517117/