I have a weird problem with our iOS app (iPhone) since we bumped to XCode 4.5.x & SDK 6. The problem is that the view controller is shown most of the times, but sometimes not. I have checked that in all cases the viewDidLoad
, viewWillAppear
and viewDidAppear
delegate methods are getting called, but that doesn't seem to influence whether the view is shown.
BroadcastOptionsViewController *tmpView = [[BroadcastOptionsViewController alloc] init];
[self.navigationController pushViewController:tmpView animated:YES];
We call this view controller from multiple places (the app uses a UITabBarController
and this code is called from two different tabs, both having their own navigation controller) and the error seems to manifest itself irrespective of via which path this is done, which leads me to suspect the view controller itself, or perhaps memory corruption.
We have tested the app on multiple devices (iOS 5.x and 6, iPhone 4/3GS, iPod touch) and it seems to occur fairly randomly (e.g. after 'cold start' as well as after using the app for a while).
Finally, I used to have the BroadcastOptionsViewController
be a subclass of a UITableViewController
. I got a suggestion to make it a UIViewController
and use a member UITableView
. That seemed to lessen the occurrence of the problem, but it still hasn't resolved it.
EDIT:
There used to be a XIB for this view controller (that wasn't used), but that has been removed. I have closed XCode, removed the app from the device, cleared the ~/Library/Developer/XCode/DerivedData/*
(known bug in XCode 4+ apparently).
By request, here's some more code:
-(id) init {
NSLog(@"BroadcastOptionsViewController:init");
self = [super init];
if (self) {
// Some scalar members initialized
}
return self;
}
-(void) viewDidLoad {
NSLog(@"BroadcastOptionsViewController:viewDidLoad");
[super viewDidLoad];
int navBarHeight = self.navigationController.navigationBar.frame.size.height;
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.bounds.size.height) style:UITableViewStyleGrouped];
[tableView setFrame:CGRectMake(0, 0, 320, self.view.bounds.size.height - navBarHeight)];
[tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]];
[tableView setDelegate:self];
[tableView setDataSource:self];
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.view addSubview:tableView];
self.title = NSLocalizedString(@"Title", nil);
self.navigationController.navigationBar.tintColor = [LookAndFeel defaultColor];
tableView.allowsSelection = YES;
UIBarButtonItem *btn_cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
self.navigationItem.leftBarButtonItem = btn_cancel;
[btn_cancel release];
UIBarButtonItem *btn_action =
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Go", nil)
style:UIBarButtonSystemItemDone
target:self
action:@selector(doAction)];
self.navigationItem.rightBarButtonItem = btn_action;
[btn_action release];
}
-(void) viewWillAppear:(BOOL) animated {
NSLog(@"BroadcastOptionsViewController:viewWillAppear");
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
// WORKAROUND: Navigation bar hiding below status bar
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
// Events
[self subscribeToApplicationEvents];
}
-(void) viewDidAppear:(BOOL)animated {
NSLog(@"BroadcastOptionsViewController:viewDidAppear");
// Always properly called, independent of whether view actually appears
}