簡體   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