Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
搜索table view parse.com iOS时无法将单元格出列_Ios_Objective C_Uitableview_Parse Platform_Uisearchdisplaycontroller - Fatal编程技术网

搜索table view parse.com iOS时无法将单元格出列

搜索table view parse.com iOS时无法将单元格出列,ios,objective-c,uitableview,parse-platform,uisearchdisplaycontroller,Ios,Objective C,Uitableview,Parse Platform,Uisearchdisplaycontroller,我试图在我的表视图中执行一个搜索函数,从Parse.com类返回对象 当我尝试在UISearchBar中进行搜索时,出现以下错误: ***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将标识符为FeaturedTableViewCell的单元格出列-必须为标识符注册nib或类,或在情节提要中连接原型单元格” 我是这样做的: @interface DiscoverViewController () <UISearchBarDe

我试图在我的表视图中执行一个搜索函数,从Parse.com类返回对象

当我尝试在UISearchBar中进行搜索时,出现以下错误:

***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将标识符为FeaturedTableViewCell的单元格出列-必须为标识符注册nib或类,或在情节提要中连接原型单元格”

我是这样做的:

@interface DiscoverViewController () <UISearchBarDelegate, UISearchDisplayDelegate>

@property (nonatomic, retain) PFQuery *query;
@property (nonatomic, retain) PFObject *category;

@end

@implementation DailyDiscoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];

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

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

    self.searchResults = [NSMutableArray array];

    _categories = [[NSMutableArray alloc] initWithCapacity:100];
}

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

    [self.searchResults removeAllObjects];

    PFQuery *query = [PFQuery queryWithClassName:@"Projects"];
    [query whereKeyExists:@"name"];
    [query whereKey:@"name" containsString:searchTerm];

    NSArray *results  = [query findObjects];

    [self.searchResults addObjectsFromArray:results];
}

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

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

- (void)refresh {

    PFQuery *query = [PFQuery queryWithClassName:@"Categories"];

    [query orderByDescending:@"name"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *posts, NSError *error) {

        if (!error) {
            //NSLog(@"%@", posts);
        } else {

        }

        [_categories setArray:posts];
        [self.tableView reloadData];
        [_loadingView stopAnimating];
        [_refreshControl endRefreshing];
    }];
}

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

    if (tableView == self.tableView) {
        if (section == 0) {
            return 1;
        } else {
            return self.categories.count;
        }
    } else {
        return self.searchResults.count;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 320;
    } else {
        return 52;
    }
}

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

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

    if (indexPath.section == 0) {

        _featuredObject = [_featured objectAtIndex:indexPath.row];

        DiscoverFeaturedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DiscoverFeaturedTableViewCell" forIndexPath:indexPath];

        [(PFFile*)_featuredObject[@"picture"] getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
            cell.image1.image = [UIImage imageWithData:data];
        }];

        return cell;
    } else {

        _category = [_categories objectAtIndex:indexPath.row];

        DiscoverTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DiscoverTableViewCell" forIndexPath:indexPath];
        cell.name.text = _category[@"name"];

        if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) {

            PFUser *obj2 = [self.searchResults objectAtIndex:indexPath.row];
            PFQuery *query = [PFQuery queryWithClassName:@"Projects"];
            PFObject *searchedUser = [query getObjectWithId:obj2.objectId];
            NSString *first = [searchedUser objectForKey:@"name"];
            cell.name.text = [first substringToIndex:1];
            cell.name.text = first;

            return cell;
        }

        return cell;
    }
}

@end

我想你可以在流程图上看到这个堆栈:

K.

好的

在viewDidLoad上尝试:

YourCustomCell*YourCustomCell=[UINib nibWithNibName:@YourCustomCell bundle:nil];[self.tableView registerNib:cellNib forCellReuseIdentifier:@cell]


注意:您的自定义单元格当然必须有.xib。

您可以试试这个,我记得遇到过这个问题,这是我尝试过的解决方案之一: [self.tableView注册表类:[DiscoverTableViewCell类]强制重用标识符:@DiscoverTableViewCell]


然而,我清楚地记得这不起作用。结果是我没有正确连接故事板中的单元。此外,请确保故事板单元的类已更改为表示单元的自定义类

你没有给我们提供最必要的信息。你的单元是从故事板还是从nib构建的?它是从故事板@PatrickBush构建的。你可以试试这个,我记得遇到过这个问题,这是我尝试过的解决方案之一:[self.tableView registerClass:[SiteFileCell类]forCellReuseIdentifier:@FileCell];