我如何 link 搜索栏以 swift/xcode 显示结果

How do I link the search bar to display results in swift/xcode

我目前正在使用 Microsoft Exchange API 开发一个应用程序,该应用程序允许我根据输入部分姓名来查找用户。我想知道如何 link 搜索栏以显示相关术语。下面我发布了我的代码/尝试

func HTTPPost(aaplication: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
    var request = NSMutableURLRequest(URL: NSURL(string: "http://mail.SAP.com/EWS/Exchange.asmx")!)
    var session = NSURLSession.sharedSession()
    request.HTTPMethod = "Post"




    return true
}
@IBOutlet weak var SearchBar: UISearchBar!

我也有这个:

HTTPGet("https://mail.SAP.com/EWS/Exchange.asmx") {
(data: String, error: String?) -> Void in
if error != nil {
    println(error)
    }
else {
    println(data)
    }
}

下面是一些示例代码,用于为您实现搜索栏 IOS 应用程序。

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate{

    @IBOutlet weak var searchBar: UISearchBar!
    @IBOutlet weak var tableView: UITableView!

    var searchActive : Bool = false
    var data = ["San Francisco","New York","San Jose","Chicago","Los Angeles","Austin","Seattle"]
    var filtered:[String] = []

    override func viewDidLoad() {
        super.viewDidLoad()

        /* Setup delegates */
        tableView.delegate = self
        tableView.dataSource = self
        searchBar.delegate = self

    }

    func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
        searchActive = true;
    }

    func searchBarTextDidEndEditing(searchBar: UISearchBar) {
        searchActive = false;
    }

    func searchBarCancelButtonClicked(searchBar: UISearchBar) {
        searchActive = false;
    }

    func searchBarSearchButtonClicked(searchBar: UISearchBar) {
        searchActive = false;
    }

    func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {

        filtered = data.filter({ (text) -> Bool in
            let tmp: NSString = text
            let range = tmp.rangeOfString(searchText, options: NSStringCompareOptions.CaseInsensitiveSearch)
            return range.location != NSNotFound
        })
        if(filtered.count == 0){
            searchActive = false;
        } else {
            searchActive = true;
        }
        self.tableView.reloadData()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if(searchActive) {
            return filtered.count
        }
        return data.count;
    }

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


        let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell;


    let label:UILabel = cell.viewWithTag(1) as UILabel



        if(searchActive){
            Label.text = filtered[indexPath.row]
        } else {
            Label.text = data[indexPath.row];
        }

        return cell;
    }
}