【发布时间】:2019-10-04 20:55:03
【问题描述】:
请有人帮助我,我不熟悉 Objective-c。应用程序在 iOS 13 中崩溃 在控制台发现如下错误
* 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“搜索栏布局的视图丢失或分离。应用程序不得从层次结构中删除 >。'
搜索条码
UIImageView *searchBackView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 45, 320, 30)];
searchBackView.image = [UIImage imageNamed:@"search1.gif"];
searchBackView.userInteractionEnabled=YES;
searchBackView.backgroundColor=[UIColor clearColor];
[tableHeader addSubview:searchBackView];
searchBar=[[[UISearchBar alloc] init] autorelease];
searchBar.delegate=self;
[searchBar setKeyboardType:UIKeyboardTypeDefault];
searchBar.barStyle = UISearchBarIconClear;
searchBar.frame=CGRectMake(17, 3, 285, 30);
[searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search1.gif"] forState:UIControlStateNormal];
searchBar.backgroundColor=[UIColor clearColor];
[searchBackView addSubview:searchBar];
[searchBackView release];
[tableHeader addSubview:label];
for (UIView *subView in self.searchBar.subviews)
{
for (UIView *secondLevelSubview in subView.subviews){
if ([secondLevelSubview isKindOfClass:[UIImageView class]]){
[secondLevelSubview removeFromSuperview];
}
}
}
searchField = nil;
for (UIView *subView in self.searchBar.subviews)
{
for (UIView *secondLevelSubview in subView.subviews){
if ([secondLevelSubview isKindOfClass:[UITextField class]])
{
searchField = (UITextField *)secondLevelSubview;
break;
}
}
}
for (UIView *subview in searchBar.subviews)
{
for (UIView *secondLevelSubview in subview.subviews){
if ([secondLevelSubview conformsToProtocol:@protocol(UITextInputTraits)])
{
[(UITextField *)secondLevelSubview setClearButtonMode:UITextFieldViewModeNever];
}
}
}
if (searchField) {
searchField.leftViewMode = UITextFieldViewModeNever;
}
BluemenAppDelegate *delegate=(BluemenAppDelegate*)[[UIApplication sharedApplication] delegate];
if (isShowlist==YES) {
delegate.search_string = @"";
searchBar.text = delegate.search_string;
isShowlist = NO;
}
searchBar.text = delegate.search_string;
更新
现在我可以启动应用程序,但现在如果单击应用程序中的任何文本字段,它会崩溃并给出 XPC 连接中断 错误
【问题讨论】:
-
你能不能把
searchBar=[[[UISearchBar alloc] init] autorelease];改成searchBar=[[UISearchBar alloc] init];并删除[searchBackView release];行试试? -
试过但没有运气 :-( 如果我评论
[secondLevelSubview removeFromSuperview];行,那么应用程序不会崩溃,但如果我这样做,搜索栏会出现问题 -
只是为了让我能理解你想要达到的目标,你想要一个清晰的搜索栏吗?如果您不删除提到的视图,您能否发布它的外观以及外观的屏幕截图?
标签: ios objective-c ios13