Skip to content

Instantly share code, notes, and snippets.

@dehydr8
Created March 25, 2015 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dehydr8/5f85488d776a99c90223 to your computer and use it in GitHub Desktop.
Save dehydr8/5f85488d776a99c90223 to your computer and use it in GitHub Desktop.
TableView - Stuff
//
// ViewController.m
// ReappearingNavigationBarSample
//
// Created by Osama Khalid on 25/03/2015.
// Copyright (c) 2015 Folio3. All rights reserved.
//
#import "ViewController.h"
@interface ViewController () <UITableViewDataSource, UITableViewDelegate> {
BOOL hidden;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
@implementation ViewController
@synthesize tableView = _tableView;
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.tableView.contentInset = UIEdgeInsetsMake(-64,0,0,0);
hidden = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0)
return 200;
return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = nil;
if (indexPath.row == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"PictureCell"];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"ExampleCell"];
cell.textLabel.text = @"Hello";
cell.detailTextLabel.text = @"Some detail";
}
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y > 150) {
if (hidden) {
NSLog(@"Y: %.1f", scrollView.contentOffset.y);
hidden = NO;
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = nil;
self.navigationController.navigationBar.translucent = NO;
}
} else {
if (!hidden) {
NSLog(@"Y: %.1f", scrollView.contentOffset.y);
hidden = YES;
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment