ios - 在 Xcode 中将 View Controller 连接到侧边栏

标签 ios swift xcode uiblureffect

我正在使用 Brian Advent 的视频,了解如何使用 UIBlur 效果制作模糊的侧边栏 (https://www.youtube.com/watch?v=qaLiZgUK2T0)。然而,在他的视频中,他没有解释如何将表格的每个项目链接到一个单独的 View Controller ——他只解释了如何使单个 View Controller 变为红色。有人可以向我解释如何做到这一点吗?相关代码如下:

func sideBarDidSelectButtonAtIndex(index: Int) {
    if index == 0{
        imageView.backgroundColor = UIColor.whiteColor()
        imageView.image = nil
    } else if index == 1{
        imageView.backgroundColor = UIColor.clearColor()
        imageView.image = UIImage(named: "image2")
    }
}

最佳答案

sideBar = SideBar(sourceView: self.view, menuItem: ["first item", "second item", "funny item"])

此自定义边栏仅在“sourceView”(一个 View Controller )上可用。所以你不能将每个项目——“tableView 的行”链接到一个单独的 View Controller。

如果你想推送到其他viewControllers,你可以试试这个:

func sideBarDidSelectButtonAtIndex(index: Int) {
if index == 0{
    imageView.backgroundColor = UIColor.whiteColor()
    imageView.image = nil
} else if index == 1{
    imageView.backgroundColor = UIColor.clearColor()
    imageView.image = UIImage(named: "image2")
} else if index == 2 {
    let secondVC = storyboard.instantiateViewControllerWithIdentifier("secondVC") as! secondVC
    //set some properties of secondVC here
    self.navigationController?.pushViewController(secondVC, animated: true)
}

关于ios - 在 Xcode 中将 View Controller 连接到侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38669555/

相关文章:

ios - 在另一个上下文中发生更改后,如何正确地从 NSFetchedResultsController 执行Fetch?

ios - 关于 UIGestureRecognizers,需要说明

ios - 读取本地化字符串

ios - 水平 Collection View 内容宽度和间距

ios - 如何使用高度计? (增减法)

swift - 为什么 NotificationCenter 没有正确传递 NSPoint?

ios - 处理 UICollectionView 单元格上的滑动 : implement handler on UICollectionView or on each cell?

swift - 当 UITableView 为空时显示消息

swift - Xcode 设计数据

xcode - 为什么 iPhone 5 不会倒转