Ios UITableview搜索分析-无结果

Ios UITableview搜索分析-无结果,ios,objective-c,uitableview,parse-platform,Ios,Objective C,Uitableview,Parse Platform,我正在尝试使用ui搜索栏来查找特定人的所有对象。我将其设置为每个PFUser或user在点的主对象中都有一个name对象。当我尝试查找用户和对象时,没有任何显示,但在NSLogs中我获得了所有信息。我想我的问题出在单元格中的rowatinexpath,但我不知道为什么 首先我要问: - (PFQuery *)queryForTable { PFQuery *query = [PFQuery queryWithClassName:@"points"]; // The key o

我正在尝试使用
ui搜索
栏来查找特定人的所有对象。我将其设置为每个
PFUser
或user在
点的主对象中都有一个name对象。当我尝试查找用户和对象时,没有任何显示,但在NSLogs中我获得了所有信息。我想我的问题出在
单元格中的rowatinexpath
,但我不知道为什么

首先我要问:

- (PFQuery *)queryForTable {
    PFQuery *query = [PFQuery queryWithClassName:@"points"];


    // The key of the PFObject to display in the label of the default cell style
    //self.textKey = @"opponent";

    // Uncomment the following line to specify the key of a PFFile on the PFObject to display in the imageView of the default cell style
    // self.imageKey = @"image";

    // Whether the built-in pull-to-refresh is enabled
    self.pullToRefreshEnabled = YES;

    // Whether the built-in pagination is enabled
    self.paginationEnabled = NO;

    // The number of objects to show per page
    self.objectsPerPage = 50;
  //where you set the username to the specific user to get only this user's post.
    // If no objects are loaded in memory, we look to the cache first to fill the table
    // and then subsequently do a query against the network.

    if (self.objects.count == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;
    }

    [query orderByDescending:@"createdAt"];

    return query;
}
我把我的酒吧:

-(void)viewDidAppear:(BOOL)animated{
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];

self.tableView.tableHeaderView = self.searchBar;

self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];

self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
self.searchController.delegate = self;


//CGPoint offset = CGPointMake(0, self.searchBar.frame.size.height);
//self.tableView.contentOffset = offset;

self.searchResults = [NSMutableArray array];
}
筛选结果:

    -(void)filterResults:(NSString *)searchTerm {

        [self.searchResults removeAllObjects];

        PFQuery *query = [PFQuery queryWithClassName: @"points"];
        [query whereKeyExists:@"name"];  //this is based on whatever query you are trying to accomplish
        [query whereKeyExists:@"opponent"]; //this is based on whatever query you are trying to accomplish
        [query whereKey:@"name" containsString:searchTerm];

        NSArray *results  = [query findObjects];

        NSLog(@"%@", results);
        NSLog(@"%u", results.count);

        [self.searchResults addObjectsFromArray:results];
    }

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    [self filterResults:searchString];
    return YES;
}
Counting The Objects:

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

    if (tableView == self.tableView) {
        //if (tableView == self.searchDisplayController.searchResultsTableView) {

        return self.objects.count;

    } else {

        return self.searchResults.count;

    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110;
}
想把这一切都表现出来!:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
    // If you want a custom cell, create a new subclass of PFTableViewCell, set the cell identifier in IB, then change this string to match
    // You can access any IBOutlets declared in the .h file from here and set the values accordingly
    // "Cell" is the default cell identifier in a new Master-Detail Project
    static NSString *CellIdentifier = @"celltag";

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    if (tableView != self.searchDisplayController.searchResultsTableView) {
        UILabel *game = (UILabel*) [cell viewWithTag:200];
        game.text = [NSString stringWithFormat:@"V.s %@", [object objectForKey:@"opponent"]];

        UILabel *points = (UILabel*) [cell viewWithTag:201];
        points.text = [NSString stringWithFormat:@"Points: %@G, %@A, %@Pts, %@, %@Hits, %@PPG",[object objectForKey:@"goals"], [object objectForKey:@"assists"], [object objectForKey:@"totalpoints"], [object objectForKey:@"plusminus"], [object objectForKey:@"hits"],[object objectForKey:@"ppg"]];

        UILabel *date = (UILabel*) [cell viewWithTag:250];
        date.text = [object objectForKey:@"date"];

        UILabel *name = (UILabel*) [cell viewWithTag:203];
        name.text = [object objectForKey:@"name"];
    }
    if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) {


        UILabel *game = (UILabel*) [cell viewWithTag:200];
        game.text = [NSString stringWithFormat:@"V.s %@", [object objectForKey:@"opponent"]];

        UILabel *points = (UILabel*) [cell viewWithTag:201];
        points.text = [NSString stringWithFormat:@"Points: %@G, %@A, %@Pts, %@, %@Hits, %@PPG",[object objectForKey:@"goals"], [object objectForKey:@"assists"], [object objectForKey:@"totalpoints"], [object objectForKey:@"plusminus"], [object objectForKey:@"hits"],[object objectForKey:@"ppg"]];

        UILabel *date = (UILabel*) [cell viewWithTag:250];
        date.text = [object objectForKey:@"date"];

        UILabel *name = (UILabel*) [cell viewWithTag:203];
        name.text = [object objectForKey:@"name"];



    }

    UILabel *game = (UILabel*) [cell viewWithTag:200];
    game.text = [NSString stringWithFormat:@"V.s %@", [object objectForKey:@"opponent"]];

    UILabel *points = (UILabel*) [cell viewWithTag:201];
    points.text = [NSString stringWithFormat:@"Points: %@G, %@A, %@Pts, %@, %@Hits, %@PPG",[object objectForKey:@"goals"], [object objectForKey:@"assists"], [object objectForKey:@"totalpoints"], [object objectForKey:@"plusminus"], [object objectForKey:@"hits"],[object objectForKey:@"ppg"]];

    UILabel *date = (UILabel*) [cell viewWithTag:250];
    date.text = [object objectForKey:@"date"];

    UILabel *name = (UILabel*) [cell viewWithTag:203];
    name.text = [object objectForKey:@"name"];


    return cell;
}

您的
cellforrowatinexpath
方法中也有很多错误

(1) 它包含一个奇怪的条件语句

a.首先,您要将指针与
进行比较=操作员:

if (tableView != self.searchDisplayController.searchResultsTableView)
但随后您使用
isEqual

if ([tableView isEqual:self.searchDisplayController.searchResultsTableView])
虽然这两种方法都是足够的,而且这个条件在技术上应该是有效的,但我最好保持一致;由于
cellforrowatinexpath
中的tableView使用==或!=操作员不仅足够,而且速度更快

b.同样以这种方式使用两个ifs的形式很糟糕,因为这两个选项都有
if
语句。相反,我建议使用if-else语句:

if (tableView != self.searchDisplayController.searchResultsTableView) {

   ...

} else {

    ...
}

return cell;
c.目前,你的条件是完全没有必要的。在两个条件块中都有相同的代码,甚至在条件块之后也有相同的代码!因此,现在可以删除这两个if语句,因为if语句之外的最后一个代码是唯一真正执行的代码

(2) 但是你确实需要一个条件,即使你现在的条件是多余的

关于为什么在使用您指定的代码时表不会更改的最主要问题:

由于您使用的是Parse的
cellforrowatinexpath
方法,因此行数据将由
-(PFQuery*)queryForTable
中的信息填充,因此在当前编写代码时,对象将填充此查询的结果:

PFQuery *query = [PFQuery queryWithClassName:@"points"];
不搜索时,您可以使用此查询返回的Parse PFObject参数,但可以使用self.searchResults数组当前索引处的对象,即
[self.searchResults objectAtIndex:indexath.row]
,用于搜索时,例如:

if (tableView != self.searchDisplayController.searchResultsTableView) {

    UILabel *game = (UILabel*) [cell viewWithTag:200];
    game.text = [NSString stringWithFormat:@"V.s %@", [object objectForKey:@"opponent"]];

    UILabel *points = (UILabel*) [cell viewWithTag:201];
    points.text = [NSString stringWithFormat:@"Points: %@G, %@A, %@Pts, %@, %@Hits, %@PPG",[object objectForKey:@"goals"], [object objectForKey:@"assists"], [object objectForKey:@"totalpoints"], [object objectForKey:@"plusminus"], [object objectForKey:@"hits"], [object objectForKey:@"ppg"]];

    UILabel *date = (UILabel*) [cell viewWithTag:250];
    date.text = [object objectForKey:@"date"];

    UILabel *name = (UILabel*) [cell viewWithTag:203];
    name.text = [object objectForKey:@"name"];

} else {

    PFObject *searchResult = [self.searchResults objectAtIndex:indexPath.row];

    UILabel *game = (UILabel*) [cell viewWithTag:200];
    game.text = [NSString stringWithFormat:@"V.s %@", [searchResult objectForKey:@"opponent"]];

    UILabel *points = (UILabel*) [cell viewWithTag:201];
    points.text = [NSString stringWithFormat:@"Points: %@G, %@A, %@Pts, %@, %@Hits, %@PPG",[searchResult objectForKey:@"goals"], [searchResult objectForKey:@"assists"], [searchResult objectForKey:@"totalpoints"], [searchResult objectForKey:@"plusminus"], [searchResult objectForKey:@"hits"], [return cell; objectForKey:@"ppg"]];

    UILabel *date = (UILabel*) [cell viewWithTag:250];
    date.text = [searchResult objectForKey:@"date"];

    UILabel *name = (UILabel*) [cell viewWithTag:203];
    name.text = [searchResult objectForKey:@"name"];
}

return cell;

谢谢你的回答<代码>对象
是一个PFObjectIt是一个解析表!我真的很感谢你的帮助!我有一个2小时的截止日期,我不知道如果(tableView!=self.searchDisplayController.searchResultsTableView){…}或者{…}
我需要像这样查询
PFQuery*Query=[pfqueryQueryWithClassName:@“points”]
而不是
-(PFQuery*)queryForTable
?好的,我添加了我的建议。