0

私はGoogleの土地を広く検索し、これに関するチュートリアルを見つけましたが、それらはIOS8より前のものです. できる限りこれをつなぎ合わせようとしましたが、アプリを実行して検索バーに単語を入力すると、何も返されないか、クラッシュします。ビューの外観と、各オブジェクトの意味は次のとおりです。

スクリーンショット

ここに私の JobListViewController.m ファイルがあります:

#import "JobDetailViewController.h"
#import "JobListViewController.h"
#import "Job.h"
#import "SearchedResultCell.h"


@interface JobListViewController () <UISearchDisplayDelegate, UISearchBarDelegate> {

}

@property (nonatomic, weak) IBOutlet UISearchBar *searchedBar;
@property (nonatomic, strong) NSString *mainTitle;
@property (nonatomic, strong) NSString *subTitle;
@property (nonatomic, assign) BOOL canSearch;

@end

@interface JobListViewController ()

@end

@implementation JobListViewController
{
    NSArray *jobs;
    NSArray *searchResults;
}
@synthesize searchedBar;
@synthesize mainTitle;
@synthesize subTitle;
@synthesize canSearch;


- (id)initWithCoder:(NSCoder *)aCoder
{
    self = [super initWithCoder:aCoder];
    if (self) {
        // Custom the table

        // The className to query on
        self.parseClassName = @"Jobs";

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

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

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

        // The number of objects to show per page
        self.objectsPerPage = 10;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.searchedBar becomeFirstResponder];


}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.canSearch = 0;

}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (void)objectsWillLoad {
    [super objectsWillLoad];

    // This method is called before a PFQuery is fired to get more objects
}


- (PFQuery *)queryForTable
{
    PFQuery *query;

    if (self.canSearch == 0)
    {
        query = [PFQuery queryWithClassName:@"Jobs"];
    }
    else
    {
        query = [PFQuery queryWithClassName:@"Jobs"];

        NSString *searchThis = [searchedBar.text uppercaseString];
        [query whereKey:@"Position" containsString:searchThis];

    }


    [query orderByAscending:@"Position"];


        query.cachePolicy = kPFCachePolicyCacheThenNetwork;


    return query;
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object: (PFObject *)object
{
    static NSString *simpleTableIdentifier = @"JobCell";
        static NSString *pimpleTableIdentifier = @"JobCell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];

    SearchedResultCell *cell = [self.tableView dequeueReusableCellWithIdentifier:pimpleTableIdentifier];

    if (cell == nil) {
        cell = [[SearchedResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pimpleTableIdentifier];

        }

        [self configureSearchResult:cell atIndexPath:indexPath object:object];


    }

    // Configure the cell
    PFFile *thumbnail = [object objectForKey:@"imageFile"];
    PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
    thumbnailImageView.image = [UIImage imageNamed:@"placeholder.jpg"];
    thumbnailImageView.file = thumbnail;
    [thumbnailImageView loadInBackground];

    UILabel *positionLabel = (UILabel*) [cell viewWithTag:101];
    positionLabel.text = [object objectForKey:@"Position"];
    UILabel *rotationLabel = (UILabel*) [cell viewWithTag:102];
    rotationLabel.text = [object objectForKey:@"Rotation"];
    UILabel *locationLabel = (UILabel*) [cell viewWithTag:103];
    locationLabel.text = [object objectForKey:@"Location"];
    UILabel *typeLabel = (UILabel*) [cell viewWithTag:104];
    typeLabel.text = [object objectForKey:@"Type"];


return cell;
}

- (void) objectsDidLoad:(NSError *)error
{
    [super objectsDidLoad:error];

    NSLog(@"error: %@", [error localizedDescription]);
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showJobDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

        Job *job = [[Job alloc] init];

        JobDetailViewController *destViewController = segue.destinationViewController;

        PFObject *object = [self.objects objectAtIndex:indexPath.row];
        job.position = [object objectForKey:@"Position"];
        job.name = [object objectForKey:@"Name"];
        job.email = [object objectForKey:@"Email"];
        job.phone = [object objectForKey:@"Phone"];
        job.imageFile = [object objectForKey:@"imageFile"];
        job.rotation = [object objectForKey:@"Rotation"];
        job.location = [object objectForKey:@"Location"];
          job.type = [object objectForKey:@"Type"];
        job.clearance = [object objectForKey:@"Clearance"];
        job.job_description = [object objectForKey:@"Job_Description"];
        job.qualifications = [object objectForKey:@"Qualifications"];
        destViewController.job = job;

    }

}

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

    [self clear];

    self.canSearch = 1;

    [self.searchedBar resignFirstResponder];

    [self queryForTable];
    [self loadObjects];

}
/*
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 if (searchResults == nil) {
 return 0;
 } else if ([searchResults count] == 0) {
 return 1;
 } else {
 return [self.objects count];
 }
 }
 */
- (void)configureSearchResult:(SearchedResultCell *)cell atIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
    mainTitle = [object objectForKey:@"Position"];
    cell.mainTitle.text = mainTitle;

    subTitle = [object objectForKey:@"Type"];
    cell.detail.text = subTitle;

     // Implement this if you want to Show image
     cell.showImage.image = [UIImage imageNamed:@"placeholder.jpg"];

     PFFile *imageFile = [object objectForKey:@"imageFile"];

     if (imageFile) {
     cell.showImage.file = imageFile;
     [cell.showImage loadInBackground];
     }
}


#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    [searchedBar resignFirstResponder];

    if ([self.objects count] == indexPath.row) {
        [self loadNextPage];
    } else {
        PFObject *photo = [self.objects objectAtIndex:indexPath.row];
        NSLog(@"%@", photo);

        // Do something you want after selected the cell
    }
}

#pragma mark - UIScrollViewDelegate


- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    [self.searchedBar resignFirstResponder];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {
    [self.searchedBar resignFirstResponder];
    [self queryForTable];
    [self loadObjects];

}




@end

どこが間違っているのかわかりません。どんな助けでも大歓迎です。または、どちらかといえば、私を正しい方向に向けることができれば.

4

1 に答える 1