2016-06-11 2 views
0

스피 작동하지 searchBarSearchButtonClicked하지만 나와 함께 작동하지 않는 것은가 UISearchBar를 사용하려고 스위프트

여기 내 코드의

class searchViewController: UIViewController , UITableViewDataSource , UISearchBarDelegate{ 
    var searchResults = [String]() 
    @IBOutlet weak var searchTable: UITableView! 
    @IBOutlet weak var mySearchBar: UISearchBar! 
    override func viewDidLoad() { 
     super.viewDidLoad() 


    } 



    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return searchResults.count 
    } 

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

     let cell = searchTable.dequeueReusableCellWithIdentifier("searchCell", forIndexPath: indexPath) as! UITableViewCell 


     return cell 
    } 
    func searchBarSearchButtonClicked(searchBar: UISearchBar) { 
     print("print anything ") 
    } 

    func searchBarTextDidBeginEditing(searchBar: UISearchBar) { 
     print(self.mySearchBar.text) 
    } 



} 

내가

일이 시뮬레이터를 아무 일이없는 사용하여 키보드에서 검색 버튼을 클릭 할 때

은 내가

내가 SOMET을했다 이 너무 작동하지을 searchBarTextDidBeginEditing 시도 힌트가 틀렸어?

답변

2

코드는 괜찮지 만 mySearchBar.delegate = self으로 설정하거나 ctrl + 검색 창을 viewController로 드래그하고 대리인을 선택하여 스토리 보드에서 할 수 있습니다.

+0

그게 다 고맙습니다. :) – Muhammed