ios - 使用 Uisearchbar 加载时 Uiview 崩溃

标签 ios swift uiview uisearchbar

我正在设计一个带有搜索栏的 View ,每当我加载该 View 时它就会崩溃。设计如下

enter image description here

我收到的错误如下

*Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0x153e646f0' * First throw call stack: (0x182303164 0x18154c528 0x182310628 0x18bc7e188 0x182308b10 0x1821edccc 0x18b990b80 0x18b98f0d0 0x18be68870 0x18bffe380 0x18bffe4f8 0x18bffe0b8 0x18bb8b74c 0x18bffe380 0x18bffe4f8 0x18bffe0b8 0x18bb8b74c 0x18bffe380 0x18bffe0b8 0x18be506c8 0x18bffe380 0x18bffe4f8 0x18bffe0b8 0x18be4fa08 0x18bc2cbe0 0x18b9da8e8 0x18b8bd6a8 0x18b8bd5d8 0x18b9df878 0x18b9df564 0x18b9df3c0 0x18b9e1938 0x18ba953c8 0x18b8f25cc 0x18ba950f8 0x18b8f25cc 0x18b8f254c 0x18b8dd0f4 0x18be6180c 0x18b8f25cc 0x18b8f254c 0x18b8dd0f4 0x18b8f1e40 0x18bf4d5e4 0x18bf48b94 0x1822aacdc 0x1822a8694 0x1822a8c50 0x1821c8c58 0x184074f84 0x18b9215c4 0x100294ee8 0x181ce856c) libc++abi.dylib: terminating with uncaught exception of type NSException

View Controller类代码如下

    import UIKit

class SearchStoreViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        print ("Search Loaded")


        // Do any additional setup after loading the view.
    }

    override func viewWillAppear(_ animated: Bool) {

        //super.viewWillAppear(animated)

        //self.tabBarController?.navigationItem.title = DASHBOARD_SEARCH_VIEW_TITLE

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

经过一番研究,我发现是 SearchBar 导致了问题。如果删除搜索栏, View 加载正常。谁能帮我解决这个问题。

最佳答案

当您从搜索结果中设置图像时,请验证您是在 UIImageView 类型而不是 UIView 类型上调用 seImage: .

This error itself says that you are setting an image using UIView type object that is not possible, bcoz UIView doesn't has setImage

同时检查IBOutlet连接是否连接到UIView或UIImageView。

关于ios - 使用 Uisearchbar 加载时 Uiview 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48880604/

相关文章:

ios - 在 iOS super View 中强制布局位置和大小

ios - 我们可以从 iOS 设备向 APNs 发送推送通知吗?

ios - 我可以在 iOS 6 中直接使用 Paypal SDK 吗?

ios - 等待方法完成以启动 objective-c 中的下一个方法

ios - 我如何在 iOS swift 中制作登录屏幕的单元测试用例

ios - 无法快速停止 UIView 动画

ios - Xcode 11 - 产品/存档卡在通知扩展上

ios - 将字符串转换为 NSDate 给出错误的日期

swift - 父 View 外的 UIView 阴影

ios - 无法从 nib 实例化 UIView。 "warning: could not load any Objective-C class information"