每当按下并选择头像时,我都希望有一个模态视图。但是在使用绑定var时,没有办法知道它是否是一个空字符串..
以下代码:
struct SelectAvatarView: View {
var role: String
@State var selectedAvatar: String?
var body: some View {
NavigationView{
ZStack {
BackgroundView()
VStack {
TitleTextView(title: "Choose your avatar:")
if role == "Parent" {
ParentAvatarView(selectedAvatar: $selectedAvatar)
}
else{
ChildAvatarView(selectedAvatar: $selectedAvatar)
}
Spacer()
}.padding()
.sheet(isPresented: !(self.$selectedAvatar.isEmpty) ) { SimpleTestView()}
}
}
}
}
问题是我不知道如何检查绑定 var $selectedAvatar
。无论我写什么,错误都是:
Cannot convert value of type 'Binding<Bool>' to expected argument type 'Bool'
帮助!!!谢谢!!