2011-08-09 4 views
0

나는이 날을 찾고 있었지만 그것을 찾을 수 없었다. ...UISearchDisplay 컨트롤러를 어떻게 프로그램 적으로 추가 할 수 있습니까?

누군가 내가 튜토리얼을 가르쳐 주거나 내가해야 할 일을 말해 줄 수 있니? 설명서가 도움이되지 않았습니다 ... 내 UITableViewController 클래스에 xib가 필요하지 않습니다.

고마워요!

+1

본 적이 있습니까? http://stackoverflow.com/questions/2959299/gray-uisearchbar-w-matching-scope-bar-programmatically –

+0

흥미 롭습니다. : "검색 테이블보기"에 표시 할 내용을 추가하려면 어떻게해야합니까? 나는 데이터 소스가 자체라는 것을 알고 있지만 ... 더 이상 무엇을 해야할지 모르겠다. –

+1

검색 막대 위임 메소드를 구현하고 사용자가 입력 할 때 이전 데이터 소스에서 일치하는 행을 선택하고 새 것을 만들고 새 데이터 소스의 내용으로 테이블을 다시로드하십시오. –

답변

1

우선은있는 tableview와 searchtableview 모두 동일한 데이터 소스를 사용하기 때문에 그런 다음 경우를 삽입해야

Gray UISearchBar w/matching scope bar programmatically을이 같이있는 tableview의 대리자 메서드에서 문 :

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (tableView == self.searchDisplayController.searchResutsTableView) { 
     tableViewData = searchResultsData objectatindex...; //array with filtered data 
    } else { 
     tableViewData = defaultData objectatindex...; //array with unfiltered data 
    } 
} 

가 동일한 작업을 수행 행의 수 대리 방법 :

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (tableView == self.searchDisplayController.searchResultsTableView) { 
     return searchResultsData.count; 
    } else { 
     return defaultData.count; 
    } 
} 

그런 다음 검색 텍스트 변경 또는 검색 버튼을 누르면 (UISearchBar delete 게이트 메소드), 표시 할 데이터를 다시로드하십시오.

관련 문제