Post

Replies

Boosts

Views

Activity

NaviagtionBar item doesn't appear
Hi, I added a navigationItem to my navigation bar but unfortunately it doesn't appear in the simulator. import UIKit class ViewController: UITabBarController {     override func viewDidLoad() {         super.viewDidLoad() // there are more view controllers   let vc2 = SecondViewController()             self.setViewControllers([vc2], animated: false)             guard let items = self.tabBar.items else {                 return             }             let images = ["house", "bell", "person.circle","person.circle"]                        for x in 0..<items.count {                 //items[x].badgeValue= "1"                 items[x].image = UIImage(systemName: images[x])             }             self.tabBar.tintColor = .black                    }     } the relevant code of the SecondViewController class SecondViewController: UINavigationController {  override func viewDidLoad() {         title = "Decount timers"         super.viewDidLoad()       view.backgroundColor = .systemBackground         navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action:  #selector(didTapAddButton))       } } Thank you for your help
1
0
432
Jan ’22
function "picker " can't be found and I don't understand why
Hello, below are the lines of code where the error is found. It seems to me that I have declared the function "picker" ( UIDatePicker) however I get an error that "Cannot find 'picker' in scope" ( the error is displayed on line 66, next to " let pickedDatetime = picker.time" import UIKit     class DateViewController: UIViewController, UITextFieldDelegate {         private let field: UITextField = {               let field = UITextField(frame: CGRect (x: 220, y: 220, width: 100, height: 100))                field.placeholder = "Enter Text"             field.becomeFirstResponder()                return field             }()         private let Buttonb: UIButton = {             let Buttonb = UIButton(frame: CGRect (x: 157, y: 470, width: 100, height: 150))             Buttonb.addTarget(self, action: #selector(didTapButtonValidate), for: .touchUpInside)            Buttonb.setTitle( "save", for: .normal)             Buttonb.addTarget(self, action: #selector(didTapButtonValidate), for: .touchUpInside)             return Buttonb         }()         private let returnButton = UIButton()         public var completionHandler: ((String, Date) -> Void)?         override func viewDidLoad() {             super.viewDidLoad()             view.backgroundColor = .systemTeal             view.addSubview(field)             view.addSubview(Buttonb)             field.becomeFirstResponder()             field.delegate = self                          let picker = UIDatePicker()             picker.datePickerMode = .time             picker.timeZone = NSTimeZone.local             picker .frame = CGRect(x: 10,y : 50, width: self.view.frame.width, height: 200)             self.view.addSubview(picker)                                       title = "New timer"                                          navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Dismiss",                                                                         style: .plain,                                                                         target: self,                                                                         action: #selector(dismissSelf))                                   returnButton.setTitle("Push Another controller", for: .normal)                     view.addSubview(returnButton)                     returnButton .backgroundColor = .white                     returnButton.setTitleColor(.black, for: .normal)                     returnButton.frame = CGRect(x: 100, y: 100, width: 200, height: 52)                     returnButton.addTarget(self, action: #selector(didTapreturmButton), for: .touchUpInside)         }         @objc private func didTapButtonValidate( sender: UIButton) {             if let text = field.text, !text.isEmpty { // the mistake "Cannot find 'picker' in scope" is displayed just below             let pickedDatetime = picker.time                 completionHandler?(text, pickedDatetime)                 navigationController?.popToRootViewController(animated: true)             }         }         @objc private func didTapreturmButton(){                 let vc = SecondViewController()                 vc.view.backgroundColor = .white                 navigationController?.pushViewController(vc, animated: true)             }             @objc private func dismissSelf() {                 dismiss(animated: true, completion: nil)             }                  func textFieldShouldReturn(_ textField: UITextField) -> Bool {             textField.resignFirstResponder()             return true         }     }``` When I add the function over the override func like that ```Swift         private let picker = UIDatePicker {         picker.datePickerMode = .time                         return picker         }()         ``` **** I get the error message "No exact matches in call to initializer " which I don't understand either. However the other error message disappears afterwards. Does anyone know how to fix this problem? Thanks in advance****
2
0
670
Dec ’21