- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 SwiftUI 中有一系列 View 。一个是“菜单 View ”,它由 组成。列表的 导航链接 包裹在 导航 View 。
代码如下。
var body: some View {
NavigationView {
List {
HStack {
NavigationLink(destination: History(), isActive: $isHistoryViewActive) {
Image(systemName: "clock")
Text("History")
}
}
HStack {
NavigationLink(destination: Settings(), isActive: $isSettingsActive) {
Image(systemName: "gear")
Text("Settings")
}
}
HStack {
Image(systemName: "info.circle.fill")
Button(action: {
...
}) {
Text("My Button")
}
}
}
}
}
设置 观点如下
var body: some View {
List {
...
Section(header: "Background Music") {
Toggle("Play", isOn: $isBackGroundMusicOn)
}
Section(header: "Voice Setting") {
HStack {
NavigationLink(destination: VoiceList() {
Text(self.voiceNames[self.selectedVoice])
}
}
}
}
最后,
语音列表观点如下:
var body: some View {
List {
ForEach(0 ..< VoiceList.voiceNames.count) {voiceIndex in
HStack {
Button(action: {
voiceChanged(selectedVoice: voiceIndex)
}){
Text(VoiceList.voiceNames[voiceIndex])
}
Spacer()
Image(systemName: "checkmark")
.frame(alignment: .trailing)
.foregroundColor(.blue)
.isHidden(hidden: voiceIndex != selectedVoice)
}
}
}
}
我遇到的问题是当应用程序从
返回时语音列表查看到
设置 查看,
导航链接保持突出显示,就好像它仍然处于事件状态,如附加的屏幕截图所示。老实说,我不知道是什么导致了这种情况。任何想法或见解都非常感谢。
最佳答案
您可以使用 onReceive
对 List
的操作:
List {
…
}.onReceive(NotificationCenter.default.publisher(for: UITableView.selectionDidChangeNotification)) {
guard let tableView = $0.object as? UITableView,
let selectedRow = tableView.indexPathForSelectedRow else { return }
tableView.deselectRow(at: selectedRow, animated: true)
}
这将取消选择所选行。
关于ios - 返回上一个 View 后,SwiftUI NavigationLink 突出显示保持突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65411477/
我和我的团队目前正在 SwiftUI 中开发 Mastodon 客户端,我有一个简单的 StatusView,用于显示所有帖子数据,目前看起来像这样: 这个 View ,在我的项目中被称为 Statu
我正在设计一个应用程序,其中包含检索 JSON 数据并在 FileBrowser 类型 View 中显示检索到的项目列表的功能。在此 View 中,用户应该能够单击文件夹以深入了解文件树,或单击文件以
我有一个 Form 中的项目列表在 NavigationView , 每个都有一个可以通过 NavigationLink 访问的详细 View . 当我向列表中添加一个新元素时,我想显示它的详细 Vi
我无法阻止 SwiftUI 的 NavigationLink 在 List 中被激活,我有这段简单的代码,其中在决定是否显示详细信息页面之前,我需要进行某种业务检查(在真实世界的应用程序中,按钮操作中
我正在制作一个应用程序,我在其中输入两个数字,并希望在单击按钮时在第二个屏幕中显示数字的相加结果。我可以在控制台中打印结果,但不幸的是,按钮周围的导航链接似乎不起作用。如果我将 NavigationL
我可能遗漏了一些东西,但我无法让 NavigationLink 在列表中工作。 我正在使用 NavigationLink(destination, tag, selection) 并且我想通过点击按钮
我的 iPad 应用有以下代码: struct ContentView: View { @State var selectionIndex: Int? = nil var body:
我有一个简单的用例,其中一个屏幕使用 NavigationLink 推送另一个屏幕。 iOS 14.5 beta (1, 2, 3) 有一个奇怪的行为,推送的屏幕在被推送后就弹出。 我设法创建了一个示
这个问题在这里已经有了答案: SwiftUI NavigationLink Button is gray and untouchable (2 个回答) 2年前关闭。 import SwiftUI s
有没有办法隐藏自动添加的导航链接 View 右侧的箭头? 我想使用 NavigationView -> List -> HStack -> NavigationLink_1 - NavigationL
我有一个带有一堆 NavigationLink 的 NavigationView。当用户点击“添加”按钮时,我想在 View 中创建一个新项目并自动将它们发送给它。我可以这样做吗? 最佳答案 Swif
我试图在出现时以编程方式触发 NavigationLink,但在所有情况下,目标 View 都会在出现后立即弹出 (iOS 13.3.1, Xcode 11.3.1) . 设置如下:ContentVi
我正在开发一个登录应用程序,登录后列出了类别。在每个类别下,都有一些横向列出的项目。事情是登录后,出现主页,一切都很好。当您单击某个项目时,它会进入详细屏幕,但是当您尝试返回时,它就会崩溃。我找到了这
我想显示一些数据的类别和子类别。我有从 json 获得的数据,当一个类别没有子类别时,它们有 parent = 0 并且如果它不同于零,则可以理解该类别有子类别。 然后,我希望从护理人员列表中根据 p
我正在开发一个需要登录的应用程序,登录后会列出类别。每个类别下都有一些水平列出的项目。问题是登录后,出现主页,所有内容都列出来了。当您单击某个项目时,它会进入详细屏幕,但当您尝试返回时,它就会崩溃。我
我正在使用 NavigatonView 和 NavigationLink,我的 View 是这样的: ScrollView{ VStack{ // MARK: - Survey
导航链接内的图像只显示为蓝色。点按图像确实可以将我们正确导航到目的地。 代码: public var body: some View { NavigationView { Im
在新版本的iOS和Xcode中 NavigationLink(isActive: , destination: , label: ) 已弃用。 那我们如何控制NavigationLink的状态呢? 最
如何更改警报中按钮的颜色和 NavigationLink 中的后退按钮?在警报按钮的文本不起作用后设置 .accentColor(.init("someColor")) 。在 navigationLi
现在我有一个导航链接 NavigationView { NavigationLink(destination: AnotherView())) { Text("Click
我是一名优秀的程序员,十分优秀!