ios - SwiftUI无法在Bundle中找到图像,但是图像在正确的路径中?

标签 ios swiftui bundle

我正在尝试从项目中的捆绑包加载图像。相反,我得到以下错误:
2020-03-20 11:38:53.032321-0400 Journey[4626:1025739] [SwiftUI] No image named 'CountryPicker.bundle/Images/AF.png' found in asset catalog for main bundle (/private/var/containers/Bundle/Application/720B947B-209E-4527-AE1C-B73D905D3D35/Journey.app)
如您在屏幕快照中所见,该图像位于捆绑包中:

enter image description here

这是我的代码:

Picker(selection: $countryOrigin, label: Text("Country of Origin")) {

    Section(header: SearchBar(text: $fetcher.searchQuery)) {

        List(fetcher.country) { country in

            HStack() {

                Image("CountryPicker.bundle/Images/\(country.id).png")


                Text(country.name)

            }

        }

    }

}

有谁知道如何解决这个问题!

更新

enter image description here

最佳答案

如果将图像移动到xcAssets,它将起作用。您也可以调用Image(uiImage(name:“imageName.png”)!)

关于ios - SwiftUI无法在Bundle中找到图像,但是图像在正确的路径中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60778215/

相关文章:

SwiftUI map : How to convert screen coordinates to map coordinates?

ios - 根据条件确定 NavigationLink 是否处于事件状态

来自命令行的 Cocoa 应用程序

Javascript bundle 和模块加载

ios - 更改 super View 会破坏 UIPanGestureRecognizer

ios - 添加一个 subview ,它是父 View 的一半

swiftui - 为什么NavigationStack的navigationDestination作为VStack的一部分没有被调用?

ios - 从 iTunesConnect 中删除测试(未批准的)应用程序

ios - 如何在iPhone真机上打开数据库sqlite文件?

android - savedInstanceState.getInt 中的第二个参数是什么?