2016-07-21 3 views
2

inputview에서 tableview를 표시하고 select에서 값을 반환하는 텍스트 필드가 있습니다. 그러나 tablebar에 표제어를 추가했지만 문제는 검색 표시기 표보기를 탭하면 자동으로 닫히고 다시 열리는 것을 의미합니다. 캔트조차 검색 창을 클릭하십시오. 어떤 충고?검색 막대가 inputView로 검색 표시 줄이있는 UITableView

다음은 코드입니다.

class myClass: UIViewController, UITableViewDataSource, UITableViewDelegate, UINavigationBarDelegate, UISearchBarDelegate { 

    //the all are in viewdidload 
    var tableView: UITableView = UITableView() 
    tableView = UITableView(frame: UIScreen.mainScreen().bounds, style: UITableViewStyle.Plain) 
    tableView.delegate  = self 
    tableView.dataSource = self 
    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") 

    let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, self.view.frame.size.width, 44)) 
    let navigationItem = UINavigationItem() 
    var searchBar:UISearchBar = UISearchBar() 
    searchBar.searchBarStyle = UISearchBarStyle.Prominent 
    searchBar.placeholder = " Search..." 
    searchBar.sizeToFit() 
    searchBar.translucent = false 
    searchBar.backgroundImage = UIImage() 
    searchBar.delegate = self 
    navigationBar.items = [navigationItem] 

    tableView.tableHeaderView = navigationBar 

    toTextField.inputView = self.tableView 

} 

답변

0

텍스트 필드를 클릭하면 텍스트 필드가 첫 번째 응답자가됩니다. 당신이 toTextField.inputView = self.tableView를 언급 했으므로; 테이블 뷰가 나타납니다.

검색 표시 줄을 클릭하면 바로 검색 표시 줄이 첫 번째 응답자입니다. TextFIeld는 더 이상 응답하지 않으므로 표가 사라집니다.

하나의 해결책은 다음과 같을 수 있습니다. 테이블보기를 입력보기에서 텍스트 필드로 만들지 마십시오. 즉 :

func textFieldDidBeginEditing(textField: UITextField) { 
    let test : UITableViewController = UITableViewController.init(style: UITableViewStyle.Plain) 
    test.tableView = self.tableView 
    let testNav: UINavigationController = UINavigationController(rootViewController: test); 
    self.presentViewController(testNav, animated: true, completion: nil) 
} 
: 가 //toTextField.inputView = self.tableView

대신 사용자가 텍스트 필드의 위임 방법 중 하나를 사용하여 테이블 뷰 컨트롤러를 제공 할 수

관련 문제