• UISearchDisplayController


    //
    //  FirstViewController.swift
    //  SearchDisplayDemo
    //
    //  Created by Bruce Lee on 24/12/14.
    //  Copyright (c) 2014 Dynamic Cell. All rights reserved.
    //
    
    import UIKit
    
    class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchDisplayDelegate, UISearchBarDelegate {
    
        @IBOutlet weak var tableView: UITableView!
        var searchBar: UISearchBar!
        var searchController: UISearchDisplayController!
        var maskView: UIVisualEffectView!
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            self.searchBar = UISearchBar(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 44))
            searchBar.delegate = self;
            self.tableView.tableHeaderView = self.searchBar
            self.searchController = UISearchDisplayController(searchBar: self.searchBar, contentsController: self)
            self.searchController.delegate = self
            var blurEffect = UIBlurEffect(style: .Light)
            maskView = UIVisualEffectView(effect: blurEffect)
            maskView.frame = UIScreen.mainScreen().bounds
            
            var testLabel = UILabel(frame: CGRectMake(100, 100, 100, 30))
            testLabel.text = "hello world"
            maskView.addSubview(testLabel)
        }
        
        // MARK: - UISearchBar delegate
        func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
            println("search")
    //        self.searchDisplayController?.searchResultsTableView.backgroundView = searchBackgroundView
            self.view.addSubview(maskView)
            return true
        }
        
        // MARK: - UISearchDisplayController delegate
        func searchDisplayController(controller: UISearchDisplayController, willHideSearchResultsTableView tableView: UITableView) {
            maskView.removeFromSuperview()
        }
        
        
        func searchDisplayControllerWillEndSearch(controller: UISearchDisplayController) {
            println("1")
            maskView.removeFromSuperview()
        }
        
        func searchDisplayControllerDidEndSearch(controller: UISearchDisplayController) {
            println("2")
        }
        
        // MARK: - UITableView delegate & datasour
    
        func numberOfSectionsInTableView(tableView: UITableView) -> Int {
            return 1
        }
        
        func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 10
        }
        
        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
            if cell == nil {
                cell = UITableViewCell(style: .Default, reuseIdentifier: "Cell")
            }
            if indexPath.row % 2 == 0{
                cell?.contentView.backgroundColor = UIColor.blueColor()
            }
            else{
                cell?.contentView.backgroundColor = UIColor.greenColor()
            }
            cell?.textLabel?.text = "(indexPath.row)"
            
            return cell!
        }
        
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    }
  • 相关阅读:
    进程(WINAPI),遍历并查找树状的进程信息,实现控制系统进程
    HDU 4786 Fibonacci Tree(生成树,YY乱搞)
    Linux信号通讯编程
    HDU 3635 Dragon Balls(带权并查集)
    还原数据库出现“未获得排他訪问”解决方法(杀死数据库连接的存储过程sqlserver)
    java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称而且未指定默认驱动程序解决方法
    【C++基础 02】深拷贝和浅拷贝
    内核链接的简单使用
    I2C测试【转】
    [RK3288]PMU配置(RK808)【转】
  • 原文地址:https://www.cnblogs.com/sunshine-anycall/p/4183777.html
Copyright © 2020-2023  润新知