zoukankan      html  css  js  c++  java
  • swift searchBar

    //

    //  SearchViewController.swift

    //  UIControlDemo

    //

    //  Created by  on 14/12/3.

    //  Copyright (c) 2014 马大哈. All rights reserved.

    //

     

    import UIKit

     

    class SearchViewController: BaseViewController , UITableViewDataSource, UITableViewDelegate ,UISearchBarDelegate{ 

        var searchBarControl: UISearchBar?

        var controlListTable:UITableView?

        var controlListArray = ["View","Lable","Button","ImageView","TextField+UIDatePicker+UIPickerView","TextView","UIActivityIndicatorView","UISlider+UIProgressView","UIScrollView+UIPageControl","UISegmentedControl+UISwitch","UIWebView","MKMapView","UIToolbar+alertview","UISearchController","UITableView","ApplicationDocument","Time/Date/UILocalNotification"]

        override func viewDidLoad() {

            super.viewDidLoad()

     

            controlListTable = UITableView(frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height), style: UITableViewStyle.Plain)

            controlListTable?.backgroundColor = .whiteColor();

            controlListTable?.delegate   = self

            controlListTable?.dataSource = self

            self.view.addSubview(controlListTable!)

        

            searchBarControl = UISearchBar(frame: CGRectMake(0.0, 0.0, 200 , 45))

            searchBarControl?.delegate = self;

            searchBarControl?.barStyle = .Default

            searchBarControl?.placeholder = "输入关键字"

            searchBarControl?.showsBookmarkButton = true

            

            /*

            searchBar放在tableheaderview  效果

            controlListTable?.tableHeaderView = searchBarControl

            */

            let rightBar = UIBarButtonItem(customView: searchBarControl!)

            self.navigationItem.rightBarButtonItem = rightBar; 

        }

        

        // 点击  取消  按钮

        func searchBarCancelButtonClicked(searchBar: UISearchBar) {

            println("点击取消按钮")

            searchBar.showsCancelButton = false

            searchBar.resignFirstResponder()

            controlListArray = ["View","Lable","Button","ImageView","TextField+UIDatePicker+UIPickerView","TextView","UIActivityIndicatorView","UISlider+UIProgressView","UIScrollView+UIPageControl","UISegmentedControl+UISwitch","UIWebView","MKMapView","UIToolbar+alertview","UISearchController","UITableView","ApplicationDocument","Time/Date/UILocalNotification"]

            controlListTable?.reloadData()

        }

     

        // 点击  搜索  按钮

        func searchBarSearchButtonClicked(searchBar: UISearchBar) {

            println("开始搜索")

            searchBar.resignFirstResponder()

            var tempArray = controlListArray

            controlListArray.removeAll()

            for temp in tempArray{

                if  temp == searchBar.text{

                    controlListArray.append(temp)

                    controlListTable?.reloadData()

                    println("开始搜索参数 : (temp)")

                }

            }

        }

        

        // 即将输入textfield

        func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {

            println("开始录入")

            searchBar.showsCancelButton = true

            searchBar.showsScopeBar = true        

            return true

        }

        

        func searchBarBookmarkButtonClicked(searchBar: UISearchBar) {

            println("点击搜索记录按钮,显示搜索历史.如果是iphone,可弹出新页面显示搜索记录。如iPad可使用popover")

            /*

            let time = TimeViewController()

            self.presentViewController(time, animated: true, completion: nil)

            */

        }

        

        func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

            return controlListArray.count;

        }

        

        func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

            return 50

        }

        

        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

            let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: nil)

            cell.textLabel?.text = String(format: "%d  %@",indexPath.row, controlListArray[indexPath.row])

            return cell

        }

     

        override func didReceiveMemoryWarning() {

            super.didReceiveMemoryWarning()

        }

    }

     

     

  • 相关阅读:
    Linux中find命令用法全汇总,看完就没有不会用的!
    ubuntu16.04 通过命令,修改屏幕分辨率
    Linux下如何查看哪些进程占用的CPU内存资源最多
    shell脚本 在后台执行de 命令 >> 文件 2>&1 将标准输出与错误输出共同写入到文件中(追加到原有内容的后面)
    ef linq 访问视图返回结果重复
    asp.net core web 本地iis开发
    jQuery控制TR显示隐藏
    mvc EF 从数据库更新实体,添加视图实体时添加不上的问题
    无法确定依赖操作的有效顺序。由于外键约束、模型要求或存储生成的值,因此可能存在依赖关系
    还原差异备份——因为没有文件可用于前滚
  • 原文地址:https://www.cnblogs.com/madaha/p/4159914.html
Copyright © 2011-2022 走看看