繁体   English   中英

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

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

请有人帮助我,我不熟悉 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。 从错误消息中可以看出,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;
        }
    }
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM