xcode - 在 Swift 上向侧边栏菜单添加功能

标签 xcode swift uiviewcontroller sidebar

所以我刚刚做了一个关于添加模糊侧边栏菜单的教程。我复制了代码,但我似乎无法找到如何调用我在 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/

相关文章:

ios - 从 JSON API 附加到数组

ios - UIViewController 生命周期调用结合状态恢复

ios - n 个 View Controller 或 n 个单元格

iphone - 可达性 - 奇怪的问题

ios - 如何在 Quickblox 中的两个用户之间创建 session ?

objective-c - Mac OS X 上的简单 Cocoa 模态窗口对话框

swift - Swift 中对象的默认相等运算符

c++ - 使用 Google 测试框架(不是 Windows)进行内存泄漏检测的标准做法是什么

json - Swift - JSON 解码返回空数组

ios - 使两个 View 具有相同的中心高度 iOS