Post

Replies

Boosts

Views

Activity

Why NavigationLink not work for text button in SwiftUI?
I have text button, and I want to use navigation link in this project, but it is not work when I click the button? Any idea?   @State var isLink = false       var body: some View {     GeometryReader { geometry in         ZStack {    NavigationLink(destination: SecondView(), isActive: $isLink) {                 Button() {                   self.isLink = true                 } label: {                                       Text("Button")                     .padding()                     .frame(width: 250, height: 50, alignment: .center)                     .foregroundColor(Color.white)                     .background(Color("color"))                     .clipShape(Capsule())                  }}}}
1
0
393
Feb ’22
How can I resize bottom sheet height?
I am using bottom sheet for my app, and it is work correctly, but I want to use the half bottom sheet, is it possible?      Image( "color")               .resizable()               .frame(width:45, height: 45)               .sheet(isPresented: $showSheet, content: {                   ScreenView()                  })
1
0
1.2k
Dec ’21
Cannot convert value of type 'AnyViewModel<BookListState, Never>.Type' to expected argument type 'AnyViewModel<BookListState, Never>'
I want to put BookListView() on the content view but it throw error like "Cannot convert value of type 'AnyViewModel<BookListState, Never>.Type' to expected argument type 'AnyViewModel<BookListState, Never>'" Any idea? BookListView: import SwiftUI struct BookListState {   var service: BookService   var books: [Book] } struct BookListView: View {   @ObservedObject var viewModel: AnyViewModel<BookListState, Never>   var body: some View {     NavigationView {       ScrollView {       VStack(alignment: .leading){       ForEach(viewModel.state.books) { book in         NavigationLink(destination: NavigationLazyView(BookDetailView(service: self.viewModel.state.service, bookId: book.id))) {           BookRow(book: book)         }       }             }       }     }   } } struct BookListView_Previews: PreviewProvider {   static var previews: some View {     let viewModel = AnyViewModel(BookListViewModel(service: MockBookService()))     return BookListView(viewModel: viewModel)   } } ContentView: import SwiftUI struct ContentView: View {   var body: some View {    BookListView(viewModel: viewModel)   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
1
0
339
Oct ’21
why it says "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"?
I have IOS projets, it work but suddenly crash and throw error like "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" Why? import Foundation import AVFoundation struct Video : Identifiable {   var id = UUID()   var player : AVPlayer   var user: User } struct User: Identifiable {   var id = UUID()   let userName: String   let userImage: String } struct MockData {   let videos: [Video] = [     Video(player: AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "reel_1", ofType: "mp4")!)),        user: User(userName: "cristiano", userImage: "user_9")),     Video(player: AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "reel_2", ofType: "mp4")!)),        user: User(userName: "mann_daar", userImage: "user_3")), ] }
1
0
947
Sep ’21
How can I use the searchable feature for my row data in SwiftUI?
I have data in row like  Text(data.user) and I want to use searchable for it, I can use search bar, bat I want to use filter for user.    Text(data.user)                   .searchable(text: $searchText, placement: .navigationBarDrawer) like here, tere is some example for filter, but how can I use it for my data. Any idea? .onChange(of: searchText) { searchText in       if !searchText.isEmpty {         articles = sampleArticles.filter { $0.title.contains(searchText) }     } else {         articles = sampleArticles     } }
3
0
460
Sep ’21
How can I hide bottom navigation bar when I click the list item?
I have bottom navigation bar and in fist view I have list item, when I click the list item, it is open detail view, but bottom navigation bar still stay in detail view, I want to hide navigation bar when I click open the detail view. Is it possible? ContentView: struct TabView : View {   @State private var selection = 0   @State var index = 0       var body: some View{           VStack(spacing: 0){               ZStack{                 ListView()                     .opacity(self.index == 0 ? 1 : 0)         }               HStack{                   Button(action: {                       self.index = 0                     }) {                       HStack(spacing: 6){                         Image("List")                              .foregroundColor(self.index == 0 ? Color("blue") : .black)                           if self.index == 0{                               Text("List")                 .foregroundColor(Color("blue"))             }                         }           .padding(.vertical,10)           .padding(.horizontal)           .background(self.index == 0 ? Color("tabbar-background") : Color.clear)           .clipShape(Capsule())         }                   Spacer(minLength: 0)                   Button(action: {                       self.index = 1                     }) {                       HStack(spacing: 6){                         Image("SecondList")                              .foregroundColor(self.index == 1 ? Color("blue") : .black)                           if self.index == 1{                               Text("SecondList")                 .foregroundColor(Color("blue"))             }                         }           .padding(.vertical,10)           .padding(.horizontal)           .background(self.index == 1 ? Color("tabbar-background"): Color.clear)           .clipShape(Capsule())         }}}     .edgesIgnoringSafeArea(.bottom)   } } ListView: struct ListView: View {   var body: some View {     VStack{       ScrollView(.vertical, showsIndicators: false, content: {         VStack(spacing: 15){             RowView(docs: docs)                       }         }         }   }     } } struct RowView: View {   @State var docs: Datas   var body: some View {          HStack(spacing: 15){       NavigationLink(destination:  ListDetailView(docs: docs)) {       HStack{       Image(docs.image)         .resizable()         .frame(width: 64, height: 48)                }       }     }     .padding(.horizontal)         } } ListDetailView: import SwiftUI struct ListDetailView: View {   @State var docs: Datas       var body: some View {                 ZStack{       Image(docs.image)         .resizable()         .aspectRatio(contentMode: .fit)             }              } } struct ListDetailView_Previews: PreviewProvider {   static var previews: some View {     ListDetailView(docs: datas[0])           } }
0
0
867
Aug ’21
Why image detail view just show one image from listview?
I have list image and when I click the image list items it show me image details, but it show same image even I click the different image? any idea? Datas:  struct Datas: Identifiable {   var id = UUID().uuidString   var name: String   var detail: String   var image: String } var datas = [   Datas(name: "People1.jpg"),   Datas(name: "People.2jpg"),   Datas(name: "People3.jpg"), ] RowView: struct RowView: View {   var docs: Datas   var body: some View {  NavigationLink(destination:  ListDetailsView(docs: datas[0])) {       Image(docs.image)         .resizable()         .frame(width: 64, height: 48)         } } ListDetailsView: struct ListDetailsView: View {    var docs: Datas       var body: some View {           ZStack{       Image(docs.image)     }         } } struct ListDetailsView_Previews: PreviewProvider {   static var previews: some View {     ListDetailsView(docs: datas[0])   } }
1
0
303
Aug ’21
Trailing closure passed to parameter of type 'Int' that does not accept a closure
I have TabView in ContentView and I want to add TabView for OnboardingView in OtherView, every things work, but it is throw error for TabView in OtherView like "Trailing closure passed to parameter of type 'Int' that does not accept a closure" I do not know why? Any idea? ContentView: struct TabView : View {       var body: some View{           VStack(spacing: 0){ ....... } OtherView:    VStack {     TabView {       ForEach(onboardingData) { onboardingItem in          OnboardingCard(onboardingItem: onboardingItem)       }   }   .tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))   .indexViewStyle(PageIndexViewStyle (backgroundDisplayMode:   .always))   .foregroundColor(.white) }
4
1
6.2k
Aug ’21
How we can use userInteractionEnabled in (number.name) for number only?
I have number.name array like 1.go, 2.java, 3.swift etc..and I do not want to edit the number again, user will only change name. Is it possible?   if words.count == 24 {         for (index, textField) in textFields.enumerated() {           textField.delegate = self           textField.firstDesign()           textField.text = "\(index + 1). \(words[index])"           mneArr.append(words[index])         }
3
0
420
Jul ’21
Change icons border when click the bottom tab bar in Swift
I have custom bottom navigation bar in IOS application, everythings work very well, and I want to change bottom navigation items tint color when I click the items, and I was use the self.imgView.image!.withRenderingMode(.alwaysTemplate) self.imgView.tintColor = .red in isSelected, and it is change whole icons border tint color. I do not know where I miss, any idea? RootStackTabViewController: class RootStackTabViewController: UIViewController { @IBOutlet weak var bottomStack: UIStackView! var currentIndex = 0 lazy var tabs: [StackItemView] = { var items = [StackItemView]() for _ in 0..<5 { items.append(StackItemView.newInstance) } return items }() lazy var tabModels: [BottomStackItem] = { return [ BottomStackItem(title: "Home", image: "home"), BottomStackItem(title: "Favorites", image: "heart"), BottomStackItem(title: "Search", image: "search"), BottomStackItem(title: "Profile", image: "user"), BottomStackItem(title: "Settings", image: "settings") ] }() override func viewDidLoad() { super.viewDidLoad() self.setupTabs() } func setupTabs() { for (index, model) in self.tabModels.enumerated() { let tabView = self.tabs[index] model.isSelected = index == 0 tabView.item = model tabView.delegate = self self.bottomStack.addArrangedSubview(tabView) } } } StackItemView: protocol StackItemViewDelegate: AnyObject { func handleTap(_ view: StackItemView) } class StackItemView: UIView { @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var imgView: UIImageView! @IBOutlet weak var highlightView: UIView! private let higlightBGColor = UIColor(hexString: "1160FB") static var newInstance: StackItemView { return Bundle.main.loadNibNamed( StackItemView.className(), owner: nil, options: nil )?.first as! StackItemView } weak var delegate: StackItemViewDelegate? override func awakeFromNib() { super.awakeFromNib() self.addTapGesture() } var isSelected: Bool = false { willSet { self.updateUI(isSelected: newValue) self.titleLabel.textColor = UIColor.white self.imgView.image!.withRenderingMode(.alwaysTemplate) self.imgView.tintColor = .red } } var item: Any? { didSet { self.configure(self.item) } } private func configure(_ item: Any?) { guard let model = item as? BottomStackItem else { return } self.titleLabel.text = model.title self.imgView.image = UIImage(named: model.image) self.isSelected = model.isSelected } private func updateUI(isSelected: Bool) { guard let model = item as? BottomStackItem else { return } model.isSelected = isSelected let options: UIView.AnimationOptions = isSelected ? [.curveEaseIn] : [.curveEaseOut] UIView.animate(withDuration: 0.4, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.5, options: options, animations: { self.titleLabel.text = isSelected ? model.title : "" let color = isSelected ? self.higlightBGColor : .white self.highlightView.backgroundColor = color (self.superview as? UIStackView)?.layoutIfNeeded() }, completion: nil) } } extension StackItemView { func addTapGesture() { let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleGesture(_:))) self.addGestureRecognizer(tapGesture) } @objc func handleGesture(_ sender: UITapGestureRecognizer) { self.delegate?.handleTap(self) } }
1
0
1k
Jul ’21
Why I am not able to click button and back to ViewController?
I am use SecondView as programmatically, I am click the button in ViewController and open SecondView controller, but I want to back to ViewController. I do not have storyboard in SecondView and I want to click the closeButton and back to ViewController. My code work but when I click the close button it is not work. Any idea? import UIKit class SecondView: UIViewController {       var closeButton = UIButton()   override func viewDidLoad() {     super.viewDidLoad()           closeButton.addTarget(self, action: #selector(dismissActionSheet), for: .touchUpInside)   }       @objc func dismissActionSheet() {     self.navigationController?.popViewController(animated: true)    } }
1
0
339
Jul ’21