Skip to content

Instantly share code, notes, and snippets.

@premedios
Created October 9, 2014 17:18
Show Gist options
  • Save premedios/16b038538ceb26384bbd to your computer and use it in GitHub Desktop.
Save premedios/16b038538ceb26384bbd to your computer and use it in GitHub Desktop.
//
// SBViewController.m
// SearchBox
//
// Created by Pedro Remedios on 14/01/14.
// Copyright (c) 2014 Pedro Remedios. All rights reserved.
//
#import "SBViewController.h"
#import "ResultTableViewCell.h"
#import "SBSearchService.h"
@interface SBViewController () <SBSearchServiceDelegate>
{
SBSearchService *searchService;
}
@end
@implementation SBViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
searchService = [[SBSearchService alloc] init];
searchService.delegate = self;
[searchService search:@"mustang"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)searchService:(SBSearchService *)searchService didFinishSearchingTerm:(NSString *)searchTerm withError:(NSError *)error {
[self.searchResultsTableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return (NSInteger)[[searchService resultData] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"result cell" forIndexPath:indexPath];
[cell configureForItem:[searchService resultData][(NSUInteger)indexPath.row]];
return cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment