开发者

Objective C UISearchBar

Hey guys, i want to know why my SearchBar dont excludes the table view cell when i search again? It just add another cell above the first.

        - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
            [searchBar setShowsCancelButton:YES animated:YES];
            self.theTableView.allowsSelection = NO;
            self.theTableView.scrollEnabled = NO;
            [theTableView setRowHeight:110];
        }

        - (void)searchDisplayController:(UISearchDisplayController *)controller
         willShowSearchResultsTableView:(UITableView *)tableView
        {
            [tableView setRowHeight:[[self theTableView] rowHeight]];
            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            [self.tableData removeAllObjects];
        }

        - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
            searchBar.text=@"";

            [searchBar setShowsCancelButton:NO animated:YES];
            [searchBar resignFirstResponder];
            self.theTableView.allowsSelection = YES;
            self.theTableView.scrollEnabled = YES;
        }


        - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
            return NO;
        }

        - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {

            // All functions goes here and bla bla bla

            [searchBar setShowsCancelButton:NO animated:YES];
            [searchBar resignFirstResponder];
            self.theTableView.allowsSelection = YES;
            self.theTableView.scrollEnabled = YES;

            //Remove tudo da table e recarrega

            [self.tableData removeAllObjects];
            [theTableView reloadData];

            [[[self searchDisplayController] searchResultsTableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone开发者_JAVA技巧:NO];

        }

Thanks


Please using a technic, which posted here with 2 tableviews and two fetch controllers. it's a little bit complicated, but u can remove part of code, which u don.t need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜