Created
November 26, 2012 21:59
-
-
Save andrewsardone/4150919 to your computer and use it in GitHub Desktop.
Programmatic UISearchDisplayController retain issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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