/* |
Copyright (C) 2015 Apple Inc. All Rights Reserved. |
See LICENSE.txt for this sample’s licensing information |
|
Abstract: |
Demonstrates vertically extending the navigation bar. |
*/ |
|
#import "ExtendedNavBarViewController.h" |
|
@interface ExtendedNavBarViewController () <UITableViewDataSource, UITableViewDelegate> |
@property (nonatomic, weak) IBOutlet UITableView *tableView; |
//! An array of city names, populated from Cities.json. |
@property (nonatomic, strong) NSArray *cities; |
@end |
|
|
@implementation ExtendedNavBarViewController |
|
//| ---------------------------------------------------------------------------- |
- (void)viewDidLoad |
{ |
[super viewDidLoad]; |
|
// Load some data to populate the table view with |
NSURL *citiesJSONURL = [[NSBundle mainBundle] URLForResource:@"Cities" withExtension:@"json"]; |
NSData *citiesJSONData = [NSData dataWithContentsOfURL:citiesJSONURL]; |
self.cities = [NSJSONSerialization JSONObjectWithData:citiesJSONData options:0 error:NULL]; |
|
// For the extended navigation bar effect to work, a few changes |
// must be made to the actual navigation bar. Some of these changes could |
// be applied in the storyboard but are made in code for clarity. |
|
// Translucency of the navigation bar is disabled so that it matches with |
// the non-translucent background of the extension view. |
[self.navigationController.navigationBar setTranslucent:NO]; |
|
// The navigation bar's shadowImage is set to a transparent image. In |
// conjunction with providing a custom background image, this removes |
// the grey hairline at the bottom of the navigation bar. The |
// ExtendedNavBarView will draw its own hairline. |
[self.navigationController.navigationBar setShadowImage:[UIImage imageNamed:@"TransparentPixel"]]; |
// "Pixel" is a solid white 1x1 image. |
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Pixel"] forBarMetrics:UIBarMetricsDefault]; |
} |
|
#pragma mark - |
#pragma mark UITableViewDataSource |
|
//| ---------------------------------------------------------------------------- |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
{ |
return self.cities.count; |
} |
|
|
//| ---------------------------------------------------------------------------- |
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
{ |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; |
if (!cell) { |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; |
} |
|
cell.textLabel.text = self.cities[indexPath.row]; |
|
return cell; |
} |
|
@end |