格式化操作增加空内容拦截和 Alert 提示
This commit is contained in:
@@ -74,6 +74,10 @@ class FormatLogViewController: UIViewController {
|
||||
}
|
||||
|
||||
@objc private func didTapFormatButton() {
|
||||
guard !trimmedText().isEmpty else {
|
||||
showEmptyAlert()
|
||||
return
|
||||
}
|
||||
if isFormatted {
|
||||
saveToFiles()
|
||||
} else {
|
||||
@@ -91,6 +95,16 @@ class FormatLogViewController: UIViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private func trimmedText() -> String {
|
||||
return textView.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
}
|
||||
|
||||
private func showEmptyAlert() {
|
||||
let alert = UIAlertController(title: "提示", message: "请输入内容后再进行格式化", preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: "确定", style: .default))
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
@objc private func didTapResetButton() {
|
||||
textView.text = ""
|
||||
isFormatted = false
|
||||
|
||||
Reference in New Issue
Block a user