Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created June 27, 2012 01:40
Show Gist options
  • Select an option

  • Save jcromartie/3000755 to your computer and use it in GitHub Desktop.

Select an option

Save jcromartie/3000755 to your computer and use it in GitHub Desktop.
halp
- (void)viewDidLoad
{
[super viewDidLoad];
UISearchBar *bar = self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
[bar sizeToFit];
bar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
bar.tintColor = [UIColor colorWithWhite:(121.0/255.0) alpha:1.0];
[self.view addSubview:bar];
UIImageView *seal = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seal"]];
seal.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
seal.alpha = 0.2;
[self.view addSubview:seal];
seal.center = self.view.center;
// initializing a search display controller sets this view controller's self.searchDisplayController property
UISearchDisplayController *searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
DebugLog(@"this actually works, by the way: %@", self.searchDisplayController);
// squish the table view frame down by the height of the search bar
CGRect tableViewFrame = self.view.bounds;
tableViewFrame.origin.y += self.searchBar.bounds.size.height;
tableViewFrame.size.height -= tableViewFrame.origin.y;
UITableView *tableView = self.tableView = [[UITableView alloc] initWithFrame:tableViewFrame style:UITableViewStylePlain];
tableView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
tableView.delegate = self;
tableView.dataSource = self;
tableView.backgroundColor = [UIColor colorWithWhite:0.47 alpha:1.0];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.scrollEnabled = NO;
[self.view addSubview:tableView];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment