Skip to content

Instantly share code, notes, and snippets.

@andrewsardone
Created November 26, 2012 21:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewsardone/4150919 to your computer and use it in GitHub Desktop.
Save andrewsardone/4150919 to your computer and use it in GitHub Desktop.
Programmatic UISearchDisplayController retain issue
#import <UIKit/UIKit.h>
@interface ExampleViewController : UIViewController
@end
#pragma mark -
@implementation ExampleViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UISearchBar *searchBar = [UISearchBar new];
// from the discussion section of -[UIViewController searchDisplayController]:
//
// > This property reflects the value of the searchDisplayController outlet
// > that you set in Interface Builder. If you create your search display
// > controller programmatically, **this property is set automatically by
// > the search display controller when it is initialized.**
//
// (emphasis mine)
id sdc = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
// passes
NSAssert(sdc == self.searchDisplayController,
@"Creating a search display controller programmatically should automatically set self.searchDisplayController");
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// fails
NSAssert(self.searchDisplayController != nil,
@"Should still have the search display controller initialized in -viewDidLoad");
}
@end
// Console
// 2012-11-26 16:57:04.356 ExampleApp[37806:c07] *** Assertion failure in -[ExampleViewController viewDidAppear:], /Users/andrew/ExampleApp/Source/ExampleViewController:
// 2012-11-26 16:57:04.358 ExampleApp[37806:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Should still have the search display controller initialized in -viewDidLoad'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment