Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am setting NavigationLink for Item,but not work with image disappeared.
struct Items: View {
var landmarks: [Landmark]
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(landmarks) { landmark in
//加了这个导航就看不到图片了,CategoryHome 也不显示图片,
//NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
Item(landmark: landmark)
//}
}
}
}
}
}
You have to embed your Scrollview into a NavigationView or it will not work
struct Items: View {
var landmarks: [Landmark]
var body: some View {
NavigationView {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(landmarks) { landmark in
//加了这个导航就看不到图片了,CategoryHome 也不显示图片,
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
Item(landmark: landmark)
}
}
}
}
}
}
}
Here is the apple tutorial for creating navigation is SwiftUI
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 13 days ago.
The community is reviewing whether to reopen this question as of 13 days ago.
Improve this question
I want to show custom drop down menu very attractive view but it does not work when I write the code as I want.
This is drop down menu approach but does not work can anyone tell the solution in any others way also.
struct DropDownList:View{
var body: some View{
Menu(content: {
HStack{
Image(systemName: "eye")
Text("Eye Clinic")
}
HStack{
Image("neuro")
Text("Neuro Hospital")
}
}, label: {
Text("Hospitals")
})
}
}
Your question isn't clear, but the menu you show in the image can be created as follows:
struct ContentView: View {
var body: some View {
HStack {
Text("Something")
DropDownList()
}
}
}
struct DropDownList:View {
var body: some View {
Menu {
Button {
} label: {
Label("Edit", systemImage: "square.and.pencil")
}
Button {
} label: {
Label("Delete", systemImage: "trash")
}
} label: {
Image(systemName: "ellipsis")
}
}
}
I am trying to use the new Pull to Refresh feature in the latest version of SWiftUI which requires a List. Enclosing the VStack in a List causes the NavigationLink to work only once. Below is a simple version of the code without the Pull To Refresh part.
There is a question that was asked 68144891 on stackoverflow and there was a refrence to a known issue link which takes you to a page not found (https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-15-beta-release-notes)
Steps o reproduce
Tap "Press Me 1" or one of the items
Tap "Show Details"
Tap Back at the top
Tap "Press Me" again will not navigate to the next screen. A grey screen blocks when you tap
The app works without the VStack
struct ContentView: View {
var body: some View {
NavigationView {
List {
VStack { // commenting VStack works
Text("Options").font(.largeTitle).bold()
ForEach(1..<5, id:\.self) { counter in
NavigationLink(destination: SubView(counter: counter)) {
Text("Press Me \(counter)").font(.headline)
}
.buttonStyle(PlainButtonStyle())
}
}
}.listStyle(.grouped)
}
}
}
struct SubView: View {
var counter: Int
#State private var showDetails = false
var body: some View {
VStack(alignment: .leading) {
Button("Show details") {
showDetails.toggle()
}
if showDetails {
Text("Clicked")
.font(.largeTitle)
}
}
}
}
Any help appreciated
Thanks much!
... follow-up to my comment
I assume you wanted this
struct ContentView: View {
var body: some View {
NavigationView {
List {
Section(Text("Options").font(.largeTitle).bold()) {
ForEach(1..<5, id:\.self) { counter in
NavigationLink(destination: SubView(counter: counter)) {
Text("Press Me \(counter)").font(.headline)
}
.buttonStyle(PlainButtonStyle())
}
}
}.listStyle(.grouped)
}
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I already have an animation made in AfterEffects that I think Lottie can turn into a format I can use for my app. What I am wondering is how can I make the app start performing this animation when it is opened until the app is done loading?
Simply show the animation view instead of your content view while it's loading
example:
struct ContentView: View {
#State var isLoading = true
var body: some View {
VStack {
if isLoading {
LoadingView()
} else {
DoneLoadingView()
}
}.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
isLoading = false
}
}
}
}
struct LoadingView: View {
var body: some View {
ProgressView()
}
}
struct DoneLoadingView: View {
var body: some View {
VStack {
Text("Hello, world!")
}
}
}
This question already has answers here:
How can I pop to the Root view using SwiftUI?
(31 answers)
Closed 2 years ago.
The screen transitions with NavigationLink.
I want to return to the first screen by clicking the button on the third screen.
How do you do it?
The following code returns from the third screen to the second screen.
struct FirstView: View {
var body: some View {
VStack {
NavigationView {
NavigationLink(
destination: SecondView()
) {
Text("next")
}
}
}
}
}
struct ThirdView: View {
#Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var body: some View {
VStack {
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}) {
Text("next")
}
}
.navigationBarTitle("Third", displayMode: .inline)
}
}
I had encountered this problem, too.
But I solved it already.
Here is the solution.
Maybe it can work.
Check this answer
This question already has answers here:
SwiftUI NavigationLink Button is gray and untouchable
(2 answers)
Closed 3 years ago.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationLink(destination: DetailView()) {
Text("Show Details")
}
}
}
struct DetailView: View {
var body: some View {
Text("Detailed")
}
}
This code gives me a gray text (or button) saying 'Show Details' which is not touchable and does not perform the intended action (navigating to DetailView). Was there a change in the API or is it a bug?
I am using the newest versions of Xcode (Xcode 11 Beta 6 and macOS Catalina 10.15 Beta 6)
Your ContentView should have a NavigationView for NavigationLink to work, and be enclosed in some 'element', here a VStack
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: DetailView()) {
Text("Show Details")
}
}
}
}
}
Hope this helps!