在 HackingWithSwift 课程之后,我正在迈出进入 SwiftUI 的第一步。尝试在我的应用中实现导航栏时遇到了问题。由于某些原因,导航栏的标题没有显示。这是我正在使用的代码:
struct ContentView: View {
var body: some View {
NavigationView {
Form {
...
}
}
.navigationBarTitle(Text("WeSplit"))
}
}
Run Code Online (Sandbox Code Playgroud)
一旦在模拟器或我的目标设备上运行它,我会看到导航栏标题的可用空间,但那里没有文本。

我也试过.navigationBarTitle("WeSplit")在没有 Text() 的情况下输入。结果还是一样。
你对如何解决它有什么想法吗?先感谢您!
我正在运行 Xcode 12.3 版。
我正在尝试在我的迷你应用程序中实现发送电子邮件功能。
这是我正在使用的代码(取自https://hackingwithswift.com):
import Foundation
import SwiftUI
import MessageUI
func sendEmail() {
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["you@yoursite.com"])
mail.setMessageBody("<p>You're so awesome!</p>", isHTML: true)
present(mail, animated: true)
} else {
// show failure alert
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
Run Code Online (Sandbox Code Playgroud)
运行我的代码时,出现以下 2 个错误:
Cannot find self in scope
Cannot find present in scope
我该如何修复它?
下面的代码占用 20 个字节。然而,有一种方法可以通过中断使其变得更小。如何?
\nA\nMOV AH,9\nMOV DX,108\nINT 21\nRET\nDB 'HELLO WORLD$'\n\nR CX\n14\nN MYHELLO.COM\nW \nRun Code Online (Sandbox Code Playgroud)\n