Reputation: 7772
So I have this code -
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
self.searchController = [[PlacesViewController alloc]initWithNibName:@"PlacesView" bundle:nil];
NSLog(@"TEXT FIELD DID BEGIN EDITIN");
self.navigationItem.hidesBackButton = YES;
[self.navigationController pushViewController:self.searchController animated:YES];
return NO;
}
The NSLog
runs, but my view doesn't appear. This is happening in a controller that has a view that exists in the navigation bar. Like this -
-(void)addSearchBar{
self.searchBarController = [[SearchBarController alloc] initWithNibName: @"SearchBar" bundle: nil];
self.navigationItem.titleView = self.searchBarController.view;
}
where addSearchBar is called in the initWithNibName
method.
Why is my view not appearing?
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
searchQuery = [[SPGooglePlacesAutocompleteQuery alloc] init];
searchDetailQuery = [[SPGooglePlacesPlaceDetailQuery alloc] init];
searchQuery.radius = 2000;
shouldBeginEditing = YES;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
return self;
}
I've also proven that the view works because when I do this -
-(void)textFieldDidBeginEditing:(UITextField *)textField{
self.searchController = [[PlacesViewController alloc]initWithNibName:@"PlacesView" bundle:nil];
//may have to be strong.
NSLog(@"SELF VIEW : %@", self.view);
textField.inputView.center = self.view.center;
textField.inputView.bounds = self.view.bounds;
textField.inputView = self.searchController.view;
}
The view appears in place of the keyboard.
Upvotes: 0
Views: 265
Reputation: 31
You can move the addSearchBar from initWithNibName
to viewDidLoad
for a try. In fact, usually in the init
method, the view doesn't initialize. The view will be lazily initialize when it is first access, usually when you show the view on the screen, and the viewDidLoad
method will be call immediately after the view is initialized. So usually the init
method only configure data related property, and the view related property usually configured in the viewDidLoad
method.
Upvotes: 1