如果文本字段不为空则执行代码
execute code if textfield is NOT empty
我的视图控制器上有一个简单的文本字段。当它为空时,我隐藏了它下面的按钮。我正在尝试对其进行编码,以便当用户输入某些内容时,下面的按钮是未隐藏的。
我对图像视图中的照片填充有类似的问题。所以我想如果我重用该代码并更改一些东西它会起作用,但它只是保持隐藏状态。
这是我目前使用的代码
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if (self.buyerBrief.text != nil){
continueButton.hidden = true
} else {
continueButton.hidden = false
}
}
根据下面的答案和评论,我尝试了以下方法,但仍然没有成功
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if (self.buyerBrief.text == "" || self.buyerBrief.text!.isEmpty){
continueButton.hidden = true
} else if (self.buyerBrief.text != ""){
continueButton.hidden = false
}
}
你问错问题了。文本字段的文本可以是非 nil
但仍然为空。您想要知道文本字段的文本是否为非 nil
,如果是,则是否为 isEmpty
.
我的视图控制器上有一个简单的文本字段。当它为空时,我隐藏了它下面的按钮。我正在尝试对其进行编码,以便当用户输入某些内容时,下面的按钮是未隐藏的。
我对图像视图中的照片填充有类似的问题。所以我想如果我重用该代码并更改一些东西它会起作用,但它只是保持隐藏状态。
这是我目前使用的代码
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if (self.buyerBrief.text != nil){
continueButton.hidden = true
} else {
continueButton.hidden = false
}
}
根据下面的答案和评论,我尝试了以下方法,但仍然没有成功
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if (self.buyerBrief.text == "" || self.buyerBrief.text!.isEmpty){
continueButton.hidden = true
} else if (self.buyerBrief.text != ""){
continueButton.hidden = false
}
}
你问错问题了。文本字段的文本可以是非 nil
但仍然为空。您想要知道文本字段的文本是否为非 nil
,如果是,则是否为 isEmpty
.