Objective-c 应用程序在 iOS 13 时崩溃(搜索栏问题)

Objective-c App crashing in iOS 13(Search bar issue)

我不熟悉Objective-c,请有人帮助我。应用程序在 iOS 13 后崩溃 在控制台中发现以下错误

* 由于未捕获的异常 'NSGenericException' 而终止应用程序,原因:'Missing or detached view for search bar layout. The application must not remove > from the hierarchy.'

搜索条码

 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。如错误消息所示,iOS 13 不允许删除 UISearchBarBackground。您可以尝试解决以下问题:

这将使搜索背景图像变得透明,而无需将其删除。

for (UIView *subView in self.searchBar.subviews) {
    for (UIView *secondLevelSubview in subView.subviews){
        if ([secondLevelSubview isKindOfClass: [UIImageView class]]) {
            secondLevelSubview.alpha = 0.0;
            break;
        }
    }
}

只需将这部分代码替换为这部分代码,然后检查它是否符合您的预期。