Skip to content

Instantly share code, notes, and snippets.

@moreindirection
Last active December 31, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moreindirection/7989417 to your computer and use it in GitHub Desktop.
Save moreindirection/7989417 to your computer and use it in GitHub Desktop.
Tab Bar issue in iOS 7
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UITabBarController* tabController = [[UITabBarController alloc] init];
tabController.viewControllers = @[
[[UINavigationController alloc] initWithRootViewController:[[FirstController alloc] init]],
[[UINavigationController alloc] initWithRootViewController:[[FirstController alloc] init]]
];
self.window.rootViewController = tabController;
return YES;
}
@end
#import <Foundation/Foundation.h>
@interface FirstController : UITableViewController
{
}
@end
#import "FirstController.h"
#import "SecondController.h"
@implementation FirstController
-(id)init
{
if( (self = [super init]) )
{
self.tabBarItem.title = @"Foo";
self.tabBarItem.image = [UIImage imageNamed:@"Tab Icon.png"];
}
return self;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = @"Click";
return cell;
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
SecondController* controller = [[SecondController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
}
@end
#import <Foundation/Foundation.h>
@interface SecondController : UIViewController
{
}
@end
#import "SecondController.h"
@implementation SecondController
-(id)init
{
if( (self = [super init]) )
{
self.hidesBottomBarWhenPushed = YES;
}
return self;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor redColor];
self.view.clipsToBounds = YES;
/* ENTER VORTEX OF DESPAIR */
// without this, there's no gap, but the view continues under the tool
// bar; with it, I get the 49-pixel gap thats making my life miserable
self.edgesForExtendedLayout = UIRectEdgeNone;
/* EXIT VORTEX OF DESPAIR */
self.navigationController.toolbarItems = @[
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:nil action:nil]
];
self.navigationController.toolbarHidden = NO;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// will log a height of 411, instead of the desired 460
NSLog(@"frame: %@", NSStringFromCGRect(self.view.frame));
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment