ios - 如何取消 TextField 编辑
问题描述
如何取消文本字段编辑。TextField
我不希望在进行选择时进行其他编辑。我自己试过了,但我做不到。
struct profile: View {
@State private var iliskiDurumlari: [String] = ["Evli", "Bekar", "Ayrı", "anan"]
@State private var iliskiVisible = false
@State private var iliski = ""
var body: some View {
VStack {
TextField("İlişki Durumu Seçiniz..", text: $iliski)
.frame(width: 300, height: 50, alignment: .center)
.padding(5)
.font(Font.system(size: 15, weight: .medium, design: .serif))
.overlay(
RoundedRectangle(cornerRadius: 30)
.stroke(Color(red: 45 / 255, green: 0 / 255, blue: 112 / 255), lineWidth: 1)
)
.actionSheet(isPresented: $iliskiVisible, content: actionSheet)
.onTapGesture {
self.iliskiVisible.toggle()
}
}
}
func actionSheet() -> ActionSheet {
ActionSheet(
title: Text("Bir İlişki Durumu Seçiniz"),
message: Text("Aşagıda"),
buttons: iliskiDurumlari.map { value in
ActionSheet.Button.default(Text(value), action: {
self.iliski = value
})
}
)
}
}
解决方案
如果您不需要此特定字段的用户输入(显示键盘),则可以Text
改用:
var body: some View {
VStack {
Text(iliski) // <- change here
.frame(width: 300, height: 50, alignment: .center)
.padding(5)
.font(Font.system(size: 15, weight: .medium, design: .serif))
.overlay(
RoundedRectangle(cornerRadius: 30)
.stroke(Color(red: 45 / 255, green: 0 / 255, blue: 112 / 255), lineWidth: 1)
)
.actionSheet(isPresented: $iliskiVisible, content: actionSheet)
.onTapGesture {
self.iliskiVisible.toggle()
}
}
}
而不是占位符添加初始值:
@State private var iliski = "İlişki Durumu Seçiniz.."
推荐阅读
- java - Java Class Boolean 不接受 null
- yodlee - 是否有可以与 Yodlee 的简单描述相媲美的格子数据字段?
- azure - “'New-AzureStorageContext' 无法识别”,但模块已安装
- ubuntu - Ubuntu/Windows 10 双启动:从 PCCT 解析 PCC 子空间时出错
- javascript - 使用 Azure SDK 发送电子邮件
- javascript - 在 node.js 中删除和添加属性到 html 字符串
- asp.net-mvc - 为什么网页被请求两次?
- javascript - Apollo Server, Graphql - 必须提供查询字符串
- android - DexArchiveMergerException 仅在发布时
- jquery - jQuery find('#id') 不适用于 Ajax 响应