gpt4 book ai didi

ios - UIView 没有出现

转载 作者:行者123 更新时间:2023-11-29 03:23:03 24 4
gpt4 key购买 nike

所以我有这段代码-

-(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;
}

NSLog 运行,但我的 View 没有出现。这发生在具有导航栏中存在的 View 的 Controller 中。像这样 -

-(void)addSearchBar{
self.searchBarController = [[SearchBarController alloc] initWithNibName: @"SearchBar" bundle: nil];
self.navigationItem.titleView = self.searchBarController.view;
}

initWithNibName 方法中调用了 addSearchBar。

为什么我的 View 没有出现?

- (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;
}

我还证明了该 View 有效,因为当我这样做时 -

-(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;
}

View 出现在键盘的位置。

最佳答案

您可以将 addSearchBar 从 initWithNibName 移动到 viewDidLoad 进行尝试。事实上,通常在 init 方法中, View 不会初始化。第一次访问 View 时,通常是在屏幕上显示 View 时, View 将被延迟初始化,并且 View 初始化后将立即调用 viewDidLoad 方法。所以通常init方法只配置数据相关的属性,而 View 相关的属性通常在viewDidLoad方法中配置。

关于ios - UIView 没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20837534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com