UISearchController不显示任何内容

时间:2015-02-11 23:52:26

标签: ios objective-c parse-platform uisearchcontroller

我遇到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没有显示任何内容......有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您是否实施了委托方法- (void)updateSearchResultsForSearchController:(UISearchController *)searchController

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