本文介绍了多行文本在SwiftUI中列表内的NavigationLink中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
多行Text
似乎不起作用.
这是代码:
struct ContentView : View {
var body: some View {
List(1...5) { _ in
NavigationLink(destination: EmptyView()) {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
.lineLimit(nil)
}
}
}
}
卸下NavigationLink
,Text
的行为符合预期.
Removing the NavigationLink
, the Text
behaves as expected.
是否可以解决此问题,或者这是一个错误?
Is there a way to fix this, or is this a bug?
推荐答案
UPDATE
似乎Beta 5解决了该错误!
UPDATE
It seems Beta 5 has solved this bug!
Beta 4和早期版本的解决方法:
似乎NavigationLink已损坏".但是您可以改用 DynamicNavigationDestinationLink .我知道它太冗长,但是如果您需要出路,就可以在这里找到.至少要等到NavigationLink更好地工作为止.
It seems NavigationLink is "broken". But you can use DynamicNavigationDestinationLink instead. I know it's too verbose, but if you need a way out, here you have it. At least until NavigationLink works better.
struct ContentView: View {
var body: some View {
NavigationView {
TopView().navigationBarTitle(Text("Top View"))
}
}
}
struct TopView: View {
let detailView = DynamicNavigationDestinationLink(id: \String.self) { data in
DetailView(passedData: data)
}
var body: some View {
List(1...5) { i in
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
.lineLimit(nil)
.tapAction { self.detailView.presentedData?.value = "Detail for Row #\(i)" }
}
}
}
struct DetailView: View {
let passedData: String
var body: some View {
Text(passedData)
}
}
这篇关于多行文本在SwiftUI中列表内的NavigationLink中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!