     }
 }
 
+// MARK: - UISearchBarDelegate
+
+extension FeedsViewController: UISearchBarDelegate {
+
+    func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
+
+        //performSegueWithIdentifier("showSearchConversations", sender: nil)
+
+        return false
+    }
+}
+
 // MARK: - UITableViewDataSource, UITableViewDelegate
 
 extension FeedsViewController: UITableViewDataSource, UITableViewDelegate {

    }
    var feeds = [DiscoveredFeed]()

    @IBOutlet weak var feedsTableView: UITableView!
    @IBOutlet private weak var activityIndicator: UIActivityIndicatorView!

    private var selectedIndexPathForMenu: NSIndexPath?

    private var filterBarItem: UIBarButtonItem?
    
    private lazy var filterStyles: [FeedSortStyle] = [
        .Distance,
        .Time,
        .Match,
    ]

    private func filterItemWithSortStyle(sortStyle: FeedSortStyle, currentSortStyle: FeedSortStyle) -> ActionSheetView.Item {
        return .Check(
            title: sortStyle.name,
            titleColor: UIColor.yepTintColor(),
            checked: sortStyle == currentSortStyle,
            action: { [weak self] in
                guard let strongSelf = self else { return }
                strongSelf.feedSortStyle = sortStyle
                strongSelf.filterView.items = strongSelf.filterItemsWithCurrentSortStyle(strongSelf.feedSortStyle)
                strongSelf.filterView.refreshItems()
            }
        )
    }

    private func filterItemsWithCurrentSortStyle(currentSortStyle: FeedSortStyle) -> [ActionSheetView.Item] {
        var items = filterStyles.map({
            filterItemWithSortStyle($0, currentSortStyle: currentSortStyle)
        })
        items.append(.Cancel)
        return items
    }

    private lazy var filterView: ActionSheetView = {
        let view = ActionSheetView(items: self.filterItemsWithCurrentSortStyle(self.feedSortStyle))
        return view
    }()

    private lazy var newFeedTypesView: ActionSheetView = {
        let view = ActionSheetView(items: [
            .Default(
                title: NSLocalizedString("Text & Photos", comment: ""),
                titleColor: UIColor.yepTintColor(),
                action: { [weak self] in
                    self?.performSegueWithIdentifier("presentNewFeed", sender: nil)
                    return true
                }
            ),
            .Default(
                title: NSLocalizedString("Voice", comment: ""),
                titleColor: UIColor.yepTintColor(),
                action: { [weak self] in
                    self?.performSegueWithIdentifier("presentNewFeedVoiceRecord", sender: nil)
                    return true
                }
            ),
            .Default(
                title: NSLocalizedString("Location", comment: ""),
                titleColor: UIColor.yepTintColor(),
                action: { [weak self] in
                    self?.performSegueWithIdentifier("presentPickLocation", sender: nil)
                    return true
                }
            ),
            .Cancel,
            ]
        )
        return view
    }()

    private lazy var skillTitleView: UIView = {

        let titleLabel = UILabel()

        let textAttributes = [
            NSForegroundColorAttributeName: UIColor.whiteColor(),
            NSFontAttributeName: UIFont.skillHomeTextLargeFont()
        ]

        let titleAttr = NSMutableAttributedString(string: self.skill?.localName ?? "", attributes:textAttributes)

        titleLabel.attributedText = titleAttr
        titleLabel.textAlignment = NSTextAlignment.Center
        titleLabel.backgroundColor = UIColor.yepTintColor()
        titleLabel.sizeToFit()

        titleLabel.bounds = CGRectInset(titleLabel.frame, -25.0, -4.0)

        titleLabel.layer.cornerRadius = titleLabel.frame.size.height/2.0
        titleLabel.layer.masksToBounds = true

        return titleLabel
    }()

    lazy var pullToRefreshView: PullToRefreshView = {

        let pullToRefreshView = PullToRefreshView()
        pullToRefreshView.delegate = self

        self.feedsTableView.insertSubview(pullToRefreshView, atIndex: 0)

        pullToRefreshView.translatesAutoresizingMaskIntoConstraints = false

        let viewsDictionary = [
            "pullToRefreshView": pullToRefreshView,
            "view": self.view,
        ]

        let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:|-(-200)-[pullToRefreshView(200)]", options: [], metrics: nil, views: viewsDictionary)

        // 非常奇怪，若直接用 "H:|[pullToRefreshView]|" 得到的实际宽度为 0
        let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[pullToRefreshView(==view)]|", options: [], metrics: nil, views: viewsDictionary)

        NSLayoutConstraint.activateConstraints(constraintsV)
        NSLayoutConstraint.activateConstraints(constraintsH)
        
        return pullToRefreshView
    }()

    #if DEBUG
    private lazy var feedsFPSLabel: FPSLabel = {
        let label = FPSLabel()
        return label
    }()
    #endif

    private let feedSkillUsersCellID = "FeedSkillUsersCell"
    private let feedBasicCellID = "FeedBasicCell"

            filterBarItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(FeedsViewController.showFilter(_:)))
            navigationItem.leftBarButtonItem = filterBarItem
        }

        if hideRightBarItem {
             navigationItem.rightBarButtonItem = nil
