2011-09-18 7 views
1

보기 1에서 푸시하면 searchBar.text를 설정하려고합니다.보기 2에 문자열을 전달하고 있지만 searchBar.text로 문자열을 설정해야합니다. 내 테이블을 걸러 낼거야. 이것은 지금까지의 코드이지만 작동하지 않는 것 같습니다.view에서 searchBar.text를 설정하면로드 됨

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = NSLocalizedString(@"Places", nil); 
    self.managedObjectContext = [self getContext]; 
    UIBarButtonItem * sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStyleBordered target:self action:@selector(sort)]; 

    self.navigationItem.rightBarButtonItem = sortButton; 
    [sortButton release]; 

    //HIT WS TO SEE LAST UPDATED AND COMPARE TO STORED LAST UPDATED DATE 
    //IF WS HAS NEWER DATE,BLOW CD AWAY AND CALL getRSSDAta 

    self.searchBar.delegate = self; 
    self.title = @"Results"; 
    self.navigationController.navigationBarHidden = NO; 

    __tableView.delegate = self; 
    __tableView.dataSource = self; 
    searchedData = [[NSMutableArray alloc]init]; 
    tableData = [[NSMutableArray alloc]init]; 
    [tableData addObjectsFromArray:_PlaceArray];//on launch it should display all the records 

    [recurringArray initWithObjects:@"Alphabetical",@"Rating Low to High", @"Rating Hight to Low", nil]; 

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_texture.png"]]; 

    self.view.backgroundColor = background; 

    [background release]; 


    recurringDate = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 190, 320, 200)]; 
    recurringDate.showsSelectionIndicator = YES; 
    recurringDate.delegate = self; 
    [recurringDate selectRow:0 inComponent:0 animated:YES]; 
    [self.view addSubview:recurringDate]; 

    recurringDate.hidden = YES; 

    NSLog(@"search text is %@", self.search); 

    searchBar.text = self.search; 
    [self searchBarSearchButtonClicked:searchBar]; 

} 

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar 
{ 
    // only show the status bar’s cancel button while in edit mode 
    useSearchData = YES; 
    self.searchBar.showsCancelButton = YES; 
    self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo; 
    // flush the previous search content 
    [tableData removeAllObjects]; 
} 

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar 
{ 
    self.searchBar.showsCancelButton = NO; 
} 

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{ 

    if([searchText isEqualToString:@""] && [__searchBar.text isEqualToString:@""]){  //if nothing is in the search bar show normal table 
     useSearchData = NO; 
     [self.tableView reloadData]; 
     [self.searchBar resignFirstResponder]; 
     return; 
    } 
    else 
    { 
      searchText = __searchBar.text; 

     useSearchData=YES; 

     NSPredicate * p = [NSPredicate predicateWithFormat:@"name contains[cd] %@",searchText]; //comparing stored locations to searchText 

     self.searchResults = [CoreDataBasicService fetchResultsForEnity:@"Place" WithPredicate:p andSortDiscriptor:@"name" Ascending:YES]; 

     [self.tableView reloadData]; 
    } 
} 

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar 
{ 
    useSearchData = NO; 

    [self.searchResults removeAllObjects]; 
    [self.tableView reloadData]; 

    [self.searchBar resignFirstResponder]; 
    self.searchBar.text = @""; 


} 

-(void)searchBarSearchButtonClicked:(UISearchBar *)_searchBar 
{ 
    [searchBar resignFirstResponder]; 
} 

답변

0

당신이 IB에서 그것을 유선 바보 소리 만 확인 수, 나는 몇 가지 코드

+0

검색 기능은 이미 원래의 테이블을 필터링한다을 방해하고 때이 일을 잊어 버렸습니다. 난 그냥 첫 번째보기에서 검색 텍스트를 설정하고 해당 문자열을 searchBar 두 번째보기에서 밀어 싶습니다. 문자열이 잘 전달되고 있습니다. 그냥 self.search라는 문자열로 searchBar 텍스트를 설정하는 것 같습니다. – Bradley

관련 문제