要运行示例项目,首先从仓库中克隆,然后在Example目录中运行pod install
。
请确保使用TableScrollNavigationController
的子类为您的UINavigationController
,使用TableScrollNavigationViewController
的子类为您的UIViewController
。
这是一个将在导航栏上创建导航表的类。您通常不需要为此类做任何事情。您可以在Storyboard中将您的UINavigationController
的类设置为,或者您可以在代码中程序化地创建一个TableScrollNavigationController
实例。
此类将把您的滚动视图附着到导航栏上(包括导航栏上的表),使其与滚动视图一起滚动。它还会将导航项推送到TableScrollNavigationController
,以在导航栏上方的表上添加该项。
使用attachScrollableView(_:)
将您的scrollView附着,以便导航栏开始跟随。
override func viewDidLoad() {
attachScrollableView(tableView)
super.viewDidLoad()
}
使用pushViewController(_:animated:title:)
将VC推送到TableScrollNavigationController
,并将item添加到导航栏上方的表中。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
if let nc = navigationController as? TableScrollNavigationController{
nc.pushViewController(vc, animated: true, title: "Section 2.1")
}
}
TableScrollNavigation通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile中
pod "TableScrollNavigation"
Cyrus Chan, [email protected]
TableScrollNavigation可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。