Post

Replies

Boosts

Views

Activity

Reply to UI Elements in TableViewCell are not working by touching, why?
This is not the code, it is something you have edited (line 109, 123, …) So please copy the exact code. And use Paste and match style to avoid all the extra lines, like this: class SearchCell: UITableViewCell, UISearchBarDelegate { let searchbar = UISearchBar() override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) addSubview(searchbar) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func setConstraints() { searchbar.placeholder = "Country, City" searchbar.searchBarStyle = .minimal let TapGesture = UITapGestureRecognizer(target: self, action: #selector(searchBarTapped)) searchbar.addGestureRecognizer(TapGesture) searchbar.isUserInteractionEnabled = true // Constraints searchbar.translatesAutoresizingMaskIntoConstraints = false searchbar.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true searchbar.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10).isActive = true searchbar.widthAnchor.constraint(equalToConstant: 380).isActive = true searchbar.heightAnchor.constraint(equalToConstant: 40).isActive = true } @objc func searchBarTapped() { searchbar.delegate = self } override func awakeFromNib() { super.awakeFromNib() { } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } } Why do you set the delegate in searchBarTapped() ? That's too late. You should have done it earlier, probably in awake or in init.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Legacy Segmented Control style?
What don't you like ? Rounded corners ? If so, could you try to subclass UISegmentedControl as follows: class SquareSegmentedControl: UISegmentedControl { override func layoutSubviews() { super.layoutSubviews() layer.cornerRadius = 0 for view in self.subviews { view.roundCorners(corners: UIRectCorner.allCorners, radius: 0) } } } If there are other points which cause problem, have a look here. https ://medium. com/flawless-app-stories/ios-13-uisegmentedcontrol-3-important-changes-d3a94fdd6763
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Multiple Table Views
Where is the other tableView ? In another ViewController ? I assume it is in another VC. have you checked that names is not empty ? You can test in viewDidLoad by adding print("number of names", names.count) Have you defined dataSource and delegate for the tableView ? You should do it directly in IB (as tableView is declared as IBOutlet) or in code. In this case, add in viewDidLoad: tableView.delegate = self tableView.dataSource = self Notes: you should give a more significant name to tableView. Such as namesTableView. To do so, right click on tableView in     @IBOutlet weak var tableView: UITableView! and select RefactorRename enter the new name (it will change everywhere, including in IB which is essential) code is hard to read lines 52/53 or 32 or 64. tableView.deselectRow(at: indexPath, animated: true)} func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) - Int { return names.count } You should mark more clearly the separation between func with an extra line: // tableView.deselectRow(at: indexPath, animated: true) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) - Int { return names.count }
Mar ’21
Reply to set UILabel's backgroundColor to nil is incorrect
 set the tt.backgroundColor is nil This should results in a transparent background color. Why nil and not .clear ? I adjust tt.text=@"abcd中" I tried (in Swift, no change). Still black if color is nil. Where do you change the value ? In viewDidLoad ? Reason may be that chinese characters are handled specially when drawing ? See this: https://stackoverflow.com/questions/48056901/setting-nil-background-for-uilabel-for-iphone-application
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Localization and tap gesture
2 years later… I finally found here inspiration here for something very close to what I wanted: https://stackoverflow.com/questions/28152526/how-do-i-open-phone-settings-when-a-button-is-clicked Button action to switch language: &#9;&#9;@objc func openSettings() { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { return } &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if UIApplication.shared.canOpenURL(settingsUrl) { &#9;&#9;&#9;&#9;&#9;&#9;UIApplication.shared.open(settingsUrl, completionHandler: nil) &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;@IBAction func toggleLanguagePopover() { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;var languages : [Language] = [] &#9;&#9;&#9;&#9;for country in Language.allLanguages { // I have defined the list of languages the app is localised for &#9;&#9;&#9;&#9;&#9;&#9;languages.append(country) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;var anAction : UIAlertAction &#9;&#9;&#9;&#9;var alertStyle = UIAlertController.Style.alert &#9;&#9;&#9;&#9;let alertController = UIAlertController( &#9;&#9;&#9;&#9;&#9;&#9;title: NSLocalizedString("Language", comment: ""), &#9;&#9;&#9;&#9;&#9;&#9;message: NSLocalizedString("Select a language, comment: "toggleLanguagePopover"), preferredStyle: alertStyle)&#9; &#9;&#9;&#9;&#9;for i in 0..<languages.count { &#9;&#9;&#9;&#9;&#9;&#9;anAction = UIAlertAction(title: languages[i].flag + " " + languages[i].fullname, style: .default, handler: { (action) -> Void in self.openSettings()} ) &#9;&#9;&#9;&#9;&#9;&#9;anAction.isEnabled = Global.shared.systemLanguage != Language.allLanguages[i] // Button for the already selected language is disabled &#9;&#9;&#9;&#9;&#9;&#9;alertController.addAction(anAction) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9; let cancelAction = UIAlertAction(title: NSLocalizedString("Ok", comment: ""), style: .destructive, handler: nil) &#9;&#9;&#9;&#9;&#9;&#9;alertController.addAction(cancelAction) &#9;&#9;&#9;&#9;present(alertController, animated: true, completion: nil) &#9;&#9;} This brings you to the app settings page with direct access to preferred languages list. Click on language and return to your app from the navigation button. You have switched the app language. It's very fast. Only caveat, the device language does not change, so settings remain displayed in device's language. But that's a really minor annoyance.
Mar ’21
Reply to Not following app guidelines and rejected build.
You got a lot of suggestions in SO. Did you try them ? Crash log seems to show problem is in InitialViewController / viewDidAppear Have you checked both segues: loginSegue and viewDashBoard Which VC do they lead to ? import UIKit class InitialViewController: UIViewController { &#9;&#9;override func viewDidLoad(){ &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;} &#9;&#9; &#9;&#9;override func viewWillAppear(_ animated: Bool) { &#9;&#9;&#9;&#9;self.navigationController?.navigationBar.barTintColor = #colorLiteral(red: 0.2196078431, green: 0.4705882353, blue: 0.9137254902, alpha: 1) &#9;&#9;&#9;&#9;self.navigationController?.navigationBar.tintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white] &#9;&#9;&#9;&#9; &#9;&#9;} &#9;&#9; &#9;&#9;override func viewDidAppear(_ animated: Bool) { &#9;&#9;&#9;&#9;super.viewDidAppear(animated) &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;print("Initial View Controller : ViewDidAppear") &#9;&#9;&#9;&#9;if UserDefaults.standard.object(forKey: "loginTokenDict") == nil { &#9;&#9;&#9;&#9;&#9;&#9;print("go to login") &#9;&#9;&#9;&#9;&#9;&#9;self.performSegue(withIdentifier: "loginSegue", sender: self) &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;print("go to dashboard") &#9;&#9;&#9;&#9;&#9;&#9;self.performSegue(withIdentifier: "viewDashBoard", sender: self) &#9;&#9;&#9;&#9;} &#9;&#9;} }
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to choose a character
What is your problem ? Is it how to present the list of characters ? If so, you have several solutions: use a segmented control (may be the simplest) insert directly in the view switches to select the character you want. create an alert with a button for each selection Please explain precisely Note: I would not use Character here which is a reserved type.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Help with idea/formation of app creation.
Hope I understand well,. So you want to propose user a list of drills to perform during its work out ? If so, it is feasible, if you have defined the logic of a "good" workout. You just have to pick (randomly ? logivally ?) as many types of drills according to the frequency you want. What is your problem precisely ?
Mar ’21