ScrollingTableViewsController v0.10

ScrollingTableViewsController v0.10

ScrollingTableViews 维护。



  • 作者:
  • Kevin Wood

ScrollingTableViewsController

ScrollingTableViewsController 是一个框架,用于帮助简化创建类似于 Instagram 通知标签页面相似的侧边栏表格视图设计。类似于 Instagram 的通知标签页。

安装

您可以使用 CocoaPods 将 ScrollingTableViewsController 添加到您的项目中。

pod ScrollingTableViewsController

使用方法

开始时通过子类化 ScrollingTableView。这完全等同于子类化 UITableView,即您以和常规 UITableView 相同的方式设置它。

class NotificationScrollingTableView: ScrollingTableView {

let notifications: [String]

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return notifications.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: reuseID, for: indexPath)
        
        let notification = notifications[indexPath.row]
        
        cell.textLabel?.text = notification
        
        return cell
    }  
}

如果您需要进行转场(segue),并且该转场将会推送到一个 UINavigationController 栈上,那么您需要子类化 ScrollingTableViewControllerWithMenu。它附带了一个方便的代理方法。如果您展示的转场使用了 ScrollingTableViewControllerWithMenu,可以直接使用。

代理

func scrollingTableView(scrollingTableView: ScrollingTableView, didSelectItemAt indexPath: IndexPath)

该代理函数类似于 UITableViewsdidSelectItemAt 代理函数,但它将选定的表格视图单元格传递到 UIScrollView。您需要检查来自哪个 ScrollingTableViewController

func scrollingTableView(scrollingTableView: ScrollingTableView, didSelectItemAt indexPath: IndexPath) {
  if scrollingTableView is ChatroomScrollingTableView {
    //Perform Logic
  }
}

启动指南

只需创建您的ScrollingTableViews实例。

let notificationScrollingTableView = NotificationScrollingTableView()
let chatroomScrollingTableView = ChatroomScrollingTableView()

然后创建一个ScrollingTableViewControllerWithMenu或其子类的实例。您需要提供一个字符串数组作为菜单名称。目前只能有一个菜单栏。计划添加不带菜单栏的滚动表格视图。

let scrollingTableViewControllerWithMenu = ScrollingTableViewControllerWithMenu(scrollingTableView: [notificationScrollingTableView, chatroomScrollingTableView], menuNames: ["Notifications", "Messages"])

然后只需将scrollingTableViewControllerWithMenu实例用作任何UIViewController

贡献

如果您想帮忙,请进行派生操作,并提交一个拉取请求。