0

我有一个问题UISearchController,它是在我的“ FindUsersTableViewController.h”文件中声明的,用于显示搜索到的用户。所以,一切都在标题中,我给你更多的细节与“ FindUsersTableViewController.m”文件的代码的重要部分:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
    self.searchController.dimsBackgroundDuringPresentation = NO;
    self.searchController.searchResultsUpdater = self;
    self.searchController.delegate = self;
    self.searchController.searchBar.frame = CGRectMake(0, 0, 320, 44);
    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.searchController.searchBar.tintColor = [UIColor blackColor];
    self.definesPresentationContext = YES;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.searchResults.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *userCellId = @"userCell";

    UserCell *userCell = [tableView dequeueReusableCellWithIdentifier:userCellId forIndexPath:indexPath];
   // "self.searchedUser" is a property declared as PFUser in the .h file
    PFUser *tempSrchUser = self.searchedUser;
   // "self.searchResults" is a property declared as NSMutableArray in the .h file too, it contains the searched users
    PFObject *searchedUser = [self.searchResults objectAtIndex:indexPath.row];

    NSString *tempUsername = [searchedUser objectForKey:tempSrchUser.username];

    userCell.usernameLbl.text = tempUsername;

    NSLog(@"retrieved appropriates usernames: %@", userCell.usernameLbl.text);

    return userCell;
}

UISearchController 不显示任何内容...有谁知道如何解决这个问题?

4

1 回答 1

0

你实现了委托方法- (void)updateSearchResultsForSearchController:(UISearchController *)searchController

? 这是必需的,您需要在此处进行过滤。

于 2015-02-23T11:40:48.010 回答