Post

Replies

Boosts

Views

Activity

Assistant not opening the correct swift file
I am trying to open the swift file so that I can Ctrl + Drag from the image cell into the swift file that I generated. The file was generated by New File - Cocao Touch class, previously. With the main.storyboard open and then choosing Assistant, I get the ViewController.h for the scene I am in and not the ExploreCell.swift file that I have just generated. The book I am following as I am a beginner, says that I should set the file as automatic but I can't seem to be able to do that. What am I doing wrong?
11
0
3.8k
Jul ’22
Type 'Segue' has no member 'restaurantList'
I am trying to learn Xcode using a book called 'iOS 14 Programming for Beginners'. Although the book is supposed to show the correct code I have found that it still raises errors when I type in the code. They also have the code online, which I have downloaded and compared to my code, yet I still get errors. Here is the file that produces the errors: // //  ExploreViewController.swift //  EatOut // //  Created by Tony Hudson on 15/07/2021 // import UIKit class ExploreViewController: UIViewController, UICollectionViewDelegate {     @IBOutlet weak var collectionView: UICollectionView!     let manager = ExploreDataManager()     var selectedCity: LocationItem?     var headerView: ExploreHeaderView!     override func viewDidLoad() {         super.viewDidLoad()         initialize()     }     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {         switch segue.identifier {         case Segue.locationList.rawValue: showLocationList(segue: segue)         case Segue.restaurantList.rawValue:   //ERROR HERE showRestaurantListing(segue: segue)         default:             print("Segue not added")         }     }     override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {         if identifier == Segue.restaurantList.rawValue { //AND HERE             guard selectedCity!= nil else { showAlert()               return false             }             return true       }         return true     } } // MARK: Private Extension private extension ExploreViewController {     func initialize() {         manager.fetch()     }     func showLocationList(segue: UIStoryboardSegue) {         guard let navController = segue.destination as? UINavigationController, let viewController = navController.topViewController as? LocationViewController else {             return         }         guard let city = selectedCity else {           return         }         viewController.selectedCity = city     }     func showRestaurantListing(segue: UIStoryboardSegue) {         if let viewController = segue.destination as? RestaurantListViewController, let city = selectedCity, let index = CollectionView.indexPathsForSelectedItems?.first { viewController.selectedType = manager.explore(at: index).name viewController.selectedCity = city         }     }     func showAlert() {         let alertController = UIAlertController(title: "Location Needed", message: "Please select a location.", preferredStyle: .alert)         let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) alertController.addAction(okAction)         present(alertController, animated: true, completion: nil)     }          @IBAction func unwindLocationCancel(segue: UIStoryboardSegue){     }     @IBAction func unwindLocationDone(segue:UIStoryboardSegue) {         if let viewController = segue.source as? LocationViewController {             selectedCity = viewController.selectedCity             if let location = selectedCity { headerView.lblLocation.text = location.full             }         }     } } // MARK: UICollectionViewDataSource extension ExploreViewController: UICollectionViewDataSource {     func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {         let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath)         headerView = header as? ExploreHeaderView         return headerView     }     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         manager.numberOfItems()     }     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "exploreCell", for: indexPath) as! ExploreCell         let item = manager.explore(at: indexPath)         cell.lblName.text = item.name         cell.imgExplore.image = UIImage(named: item.image)         return cell     } // Can anyone see why this is producing this error?```
1
0
386
Mar ’22
Can’t view Storyboard and swift code on the same screen
I am just started to learn iOS programming using Xcode. This may seem a stupid question but I can't figure out how to set the screen to show the storyboard on the left and the swift code on the right. I am new to Xcode and am working through an exercise and need the Storyboard scenes and the specific swift file where I need to drag from the scene to the swift file. I have clicked on Assistant and the assistant editor should be set to Automatic LocationViewController.swift. When I click on Assistant with Storyboard selected, it says no Assistant results, if I click on the swift file in the tabs I get 2 copies of the swift file?? I have looked for a tutorial or info on the web but can't find any info on this topic. Could someone please help?
4
0
2.9k
Mar ’22
Value of type 'UIStoryboardSegue' has no member 'indentifier'
I am trying to learn Xcode using iOS 14 Programming for Beginners (Packt Pub). I have had several problems with the code so I have been ultra careful and I can't find any mistakes. There is also another error in the code in an extension in the code. Here is a copy of the code: / //  MapViewController.swift //  EatOut // //  Created by Tony Hudson on 15/07/2021. // Links to: Item -308,318,319,320,321,324,341,352,353 import UIKit import MapKit class MapViewController: UIViewController,MKMapViewDelegate {     @IBOutlet weak var mapView: MKMapView!     let manager = MapDataManager()     var selectedRestaurant: RestaurantItem?     override func viewDidLoad() {         super.viewDidLoad()         initialize()     }     override func prepare(for segue: UIStoryboardSegue, sender: Any?){         switch segue.indentifier! { //<<Value of type 'UIStoryboardSegue' has no member 'indentifier'         case Segue.showDetail.rawValue: showRestaurantDetail(segue: segue)         default:             print("Segue not added")         }     } } // MARK: Private Extension private extension MapViewController {     func initialize() {         mapView.delegate = self         manager.fetch {(annotations) in addMap(annotations)}     }     func addMap(_ annotations: [RestaurantItem]) {         mapView.setRegion(manager.currentRegion(latDelta: 0.5, longDelta: 0.5), animated: true)         mapView.addAnnotations(manager.annotations)     }     func showRestaurantDetail (segue: UIStoryboardSegue){         if let viewController = segue.destination as? RestaurantDetailViewController, let restaurant = selectedRestaurant {             viewController.selectedRestaurant = restaurant         }     } } // MARK: MKMapViewDelegate extension MapViewController: MKMapViewDelegate { //<< Redundant conformance of 'MapViewController' to protocol 'MKMapViewDelegate'     func mapView(_ mapView: MKMapView, annotationView view:MKAnnotationView, calloutAccessoryControlTapped control: UIControl)  {         guard let annotation = mapView.selectedAnnotations.first         else{             return         }         selectedRestaurant = annotation as? RestaurantItem         self.performSegue(withIdentifier: Segue.showDetail.rawValue, sender: self)     }     func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation ) -> MKAnnotationView? {         let identifier = "custompin"         guard !annotation.isKind(of: MKUserLocation.self) else {             return nil         }         var annotationView: MKAnnotationView?         if let customAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) {             annotationView = customAnnotationView             annotationView?.annotation = annotation         } else {             let av = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)             av.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)             annotationView = av         }         if let annotationView = annotationView {             annotationView.canShowCallout = true             annotationView.image = UIImage(named: "custom-annotation")         }         return annotationView     } } I am wondering if there is some action that I have not done previously that is causing these errors. Can anyone help?
1
0
787
Sep ’21
Could not cast value of type 'Swift.Array.
I am trying to learn Xcode using iOS 14 Programming for Beginners (Packt Pub). I am now working on the part that adds the pins to the MapView, but when I run the app the map button is unresponsive (Runtime error). I get the following message in the Debug area: __2021-07-25 16:08:23.919240+0100 EatOut[1420:21167] Metal API Validation Enabled Could not cast value of type 'Swift.Array<EatOut.RestaurantItem>' (0x1c31e3588) to '__C.MKAnnotation' (0x1c31e3888). 2021-07-25 16:08:24.003987+0100 EatOut[1420:21167] Could not cast value of type 'Swift.Array<EatOut.RestaurantItem>' (0x1c31e3588) to '__C.MKAnnotation' (0x1c31e3888). Could not cast value of type 'Swift.Array<EatOut.RestaurantItem>' (0x1c31e3588) to 'C.MKAnnotation' (0x1c31e3888). CoreSimulator 757.5 - Device: iPhone SE (2nd generation) (E06FF756-9D0E-45B8-BBF5-7B393524B880) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone SE (2nd generation) I'm sure that this message means a lot to you experts, but as a beginner I haven't a clue! The runtime error is in this func, in the final line:  func addMap(_ annontations: [RestaurantItem]) {             mapView.setRegion(manager.currentRegion(latDelta: 0.5, longDelta: 0.5), animated: true)             mapView.addAnnotation(manager.annotations as! MKAnnotation) I get a build error on the final line if I do not apply the fix, which adds the as! MKAnnotation. Is the error in the .plist or does the code need altering? Please can you help? Here is the full code for the swift file: //  MapViewController.swift //  EatOut // //  Created by Tony Hudson on 15/07/2021. // import UIKit import MapKit class MapViewController: UIViewController, MKMapViewDelegate {     let manager = MapDataManager()     var selectedRestaurant: RestaurantItem?     @IBOutlet weak var mapView: MKMapView!     override func viewDidLoad() {         initialise()         func initialise() {             manager.fetch { (annotations) in addMap(annotations)             }         }         func addMap(_ annontations: [RestaurantItem]) {             mapView.setRegion(manager.currentRegion(latDelta: 0.5, longDelta: 0.5), animated: true)             mapView.addAnnotation(manager.annotations as! MKAnnotation)         }     } }
2
0
1.2k
Jul ’21
Collection view not displaying Cells
I am trying to learn Xcode using iOS 14 Programming for Beginners. I have just entered the code to add the images and titles on the explore screen and have checked the code with the code written by the author and it is correct. When the Explore screen opens in the simulator it should show the images with titles on the screen. All that I get is the header at the top! I have checked the connection for the IBOutlets and the have the dot in the circle, so they are connected. The code builds OK, so I am not sure what is wrong? How can I find what is causing this problem? I have not mastered debugging yet, would this help? Here is the ExploreCell.swift //  ExploreCellCollectionViewCell.swift //  EatOut // //  Created by Tony Hudson on 02/06/2021. // import UIKit class ExploreCell: UICollectionViewCell {     @IBOutlet weak var lblName: UILabel!     @IBOutlet weak var imgExplore: UIImageView! } Here is ExploreItem.swift //  ExploreItem.swift //  EatOut // //  Created by Tony Hudson on 02/06/2021. // import Foundation struct  ExploreItem {     var name: String     var image: String }     extension ExploreItem {         init(dict: [String:AnyObject]) {             self.name = dict["name"] as! String             self.image = dict["image"] as! String         }     } Here is ExploreDataManager.swift //  ExploreDataManager.swift //  EatOut // //  Created by Tony Hudson on 02/06/2021. // import Foundation class ExploreDataManager {     fileprivate var items: [ExploreItem] = []     func fetch() {         for data in loadData() {             items.append(ExploreItem(dict: data))         }     }     fileprivate func loadData() -> [[String: AnyObject]] {         guard let path = Bundle.main.path(forResource: "ExploreData", ofType: "plist"), let items = NSArray(contentsOfFile: path) else {             return [[:]]         }         return items as! [[String: AnyObject]]     }     func numberOfItems() -> Int {         items.count     }     func explore(at index:IndexPath) -> ExploreItem {         items[index.item]     } } I think that is as much information that I can give! Can someone point me in the right direction so that I can solve this problem?
9
0
3.2k
Jul ’21
Connecting Navigation Controller to View controller
I am trying to learn Xcode using iOS 14 Programming for Beginners. I some how made an error when working through the instructions in the book. There are 2 navigation controllers and I connected a view controller to the wrong Navigation controller. When I realised my mistake I deleted the segue between the wrong Navigation Controller and the view controller. I then Ctrl + Dragged from the correct Nav Controller to the view controller and then created a new View Controller and did the same to this controller to the other Nav controller. If I build the app every thing seems to work, except the Nav controller does not load the Map view when I click on the map icon, even though I have added the Map View to the View Controller. Please help?
3
0
2.3k
May ’21
View Controller not visible in Identity Inspector
I am trying to learn Xcode using iOS 14 Programming for Beginners. I have just created a new View Controller and created a Cocoa Touch class called RestaurantListViewController. In this I had to add 2 collection view stubs and an @IBoutlet var to the UICollectionView. The book then instructs me to click on th View Controller in the document outline, for the view controller I have just created, the click on the Identity Inspector to add the class, but it says no selection? I can't see where I am going wrong? The only warning I get is: Prototype collection view cells must have reuse indentifiers. Here is the code for the class: // //  RestaurantListViewController.swift //  EatOut // //  Created by Tony Hudson on 22/05/2021. // import UIKit class RestaurantListViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {     @IBOutlet weak var collectionView: UICollectionView!     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.     }     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) - Int {         1     }     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) - UICollectionViewCell {       return collectionView.dequeueReusableCell(withReuseIdentifier: "restaurantCell", for: indexPath)     } } Please can someone help?
3
0
1.9k
May ’21
Cancel button not working?
I am learning to code using iOS 14 Programming for beginners. I was trying to place the Tab Bar buttons and confused the correct view in the scene. I was trying to add them to the Navigation Controller scene, but should have added them to the View controller scene. When I run the code the Cancel button should return to the previous scene, but does not. How do I get rid of the actions that I have made by trying to add the tab bar to the wrong scene, assuming that this is what is causing the button not to work? I have not added any code as I don't think that will serve any purpose at this stage.
2
0
1.7k
May ’21
"Invalid parameter not satisfying: [constraint isKindOfClass:[NSLayoutConstraint class]]"
I am learning Xcode from a book 'iOS Programming for Beginners' and although I am sure I entered the text correctly I get the following error when I click on the Location button. The code builds with out error, so I don't know where the error is! Here is the code: // //  LocationViewController.swift //  LetsEat3 // //  Created by Tony Hudson on 27/04/2021. // import UIKit class LocationViewController: UIViewController, UITableViewDataSource {     @IBOutlet weak var tableView: UITableView!     override func viewDidLoad() {         super.viewDidLoad()     }     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) - Int {         10     }     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell {         let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath)         cell.textLabel?.text = "A Cell"         return cell     } } cal=n anyone explain why I get this error?
4
0
3.9k
May ’21
Assistant not opening the correct swift file
I am trying to open the swift file so that I can Ctrl + Drag from the image cell into the swift file that I generated. The file was generated by New File - Cocao Touch class, previously. With the main.storyboard open and then choosing Assistant, I get the ViewController.h for the scene I am in and not the ExploreCell.swift file that I have just generated. The book I am following as I am a beginner, says that I should set the file as automatic but I can't seem to be able to do that. What am I doing wrong?
Replies
11
Boosts
0
Views
3.8k
Activity
Jul ’22
Type 'Segue' has no member 'restaurantList'
I am trying to learn Xcode using a book called 'iOS 14 Programming for Beginners'. Although the book is supposed to show the correct code I have found that it still raises errors when I type in the code. They also have the code online, which I have downloaded and compared to my code, yet I still get errors. Here is the file that produces the errors: // //  ExploreViewController.swift //  EatOut // //  Created by Tony Hudson on 15/07/2021 // import UIKit class ExploreViewController: UIViewController, UICollectionViewDelegate {     @IBOutlet weak var collectionView: UICollectionView!     let manager = ExploreDataManager()     var selectedCity: LocationItem?     var headerView: ExploreHeaderView!     override func viewDidLoad() {         super.viewDidLoad()         initialize()     }     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {         switch segue.identifier {         case Segue.locationList.rawValue: showLocationList(segue: segue)         case Segue.restaurantList.rawValue:   //ERROR HERE showRestaurantListing(segue: segue)         default:             print("Segue not added")         }     }     override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {         if identifier == Segue.restaurantList.rawValue { //AND HERE             guard selectedCity!= nil else { showAlert()               return false             }             return true       }         return true     } } // MARK: Private Extension private extension ExploreViewController {     func initialize() {         manager.fetch()     }     func showLocationList(segue: UIStoryboardSegue) {         guard let navController = segue.destination as? UINavigationController, let viewController = navController.topViewController as? LocationViewController else {             return         }         guard let city = selectedCity else {           return         }         viewController.selectedCity = city     }     func showRestaurantListing(segue: UIStoryboardSegue) {         if let viewController = segue.destination as? RestaurantListViewController, let city = selectedCity, let index = CollectionView.indexPathsForSelectedItems?.first { viewController.selectedType = manager.explore(at: index).name viewController.selectedCity = city         }     }     func showAlert() {         let alertController = UIAlertController(title: "Location Needed", message: "Please select a location.", preferredStyle: .alert)         let okAction = UIAlertAction(title: "OK", style: .default, handler: nil) alertController.addAction(okAction)         present(alertController, animated: true, completion: nil)     }          @IBAction func unwindLocationCancel(segue: UIStoryboardSegue){     }     @IBAction func unwindLocationDone(segue:UIStoryboardSegue) {         if let viewController = segue.source as? LocationViewController {             selectedCity = viewController.selectedCity             if let location = selectedCity { headerView.lblLocation.text = location.full             }         }     } } // MARK: UICollectionViewDataSource extension ExploreViewController: UICollectionViewDataSource {     func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {         let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath)         headerView = header as? ExploreHeaderView         return headerView     }     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {         manager.numberOfItems()     }     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "exploreCell", for: indexPath) as! ExploreCell         let item = manager.explore(at: indexPath)         cell.lblName.text = item.name         cell.imgExplore.image = UIImage(named: item.image)         return cell     } // Can anyone see why this is producing this error?```
Replies
1
Boosts
0
Views
386
Activity
Mar ’22
Can’t view Storyboard and swift code on the same screen
I am just started to learn iOS programming using Xcode. This may seem a stupid question but I can't figure out how to set the screen to show the storyboard on the left and the swift code on the right. I am new to Xcode and am working through an exercise and need the Storyboard scenes and the specific swift file where I need to drag from the scene to the swift file. I have clicked on Assistant and the assistant editor should be set to Automatic LocationViewController.swift. When I click on Assistant with Storyboard selected, it says no Assistant results, if I click on the swift file in the tabs I get 2 copies of the swift file?? I have looked for a tutorial or info on the web but can't find any info on this topic. Could someone please help?
Replies
4
Boosts
0
Views
2.9k
Activity
Mar ’22
Value of type 'UIStoryboardSegue' has no member 'indentifier'
I am trying to learn Xcode using iOS 14 Programming for Beginners (Packt Pub). I have had several problems with the code so I have been ultra careful and I can't find any mistakes. There is also another error in the code in an extension in the code. Here is a copy of the code: / //  MapViewController.swift //  EatOut // //  Created by Tony Hudson on 15/07/2021. // Links to: Item -308,318,319,320,321,324,341,352,353 import UIKit import MapKit class MapViewController: UIViewController,MKMapViewDelegate {     @IBOutlet weak var mapView: MKMapView!     let manager = MapDataManager()     var selectedRestaurant: RestaurantItem?     override func viewDidLoad() {         super.viewDidLoad()         initialize()     }     override func prepare(for segue: UIStoryboardSegue, sender: Any?){         switch segue.indentifier! { //<<Value of type 'UIStoryboardSegue' has no member 'indentifier'         case Segue.showDetail.rawValue: showRestaurantDetail(segue: segue)         default:             print("Segue not added")         }     } } // MARK: Private Extension private extension MapViewController {     func initialize() {         mapView.delegate = self         manager.fetch {(annotations) in addMap(annotations)}     }     func addMap(_ annotations: [RestaurantItem]) {         mapView.setRegion(manager.currentRegion(latDelta: 0.5, longDelta: 0.5), animated: true)         mapView.addAnnotations(manager.annotations)     }     func showRestaurantDetail (segue: UIStoryboardSegue){         if let viewController = segue.destination as? RestaurantDetailViewController, let restaurant = selectedRestaurant {             viewController.selectedRestaurant = restaurant         }     } } // MARK: MKMapViewDelegate extension MapViewController: MKMapViewDelegate { //<< Redundant conformance of 'MapViewController' to protocol 'MKMapViewDelegate'     func mapView(_ mapView: MKMapView, annotationView view:MKAnnotationView, calloutAccessoryControlTapped control: UIControl)  {         guard let annotation = mapView.selectedAnnotations.first         else{             return         }         selectedRestaurant = annotation as? RestaurantItem         self.performSegue(withIdentifier: Segue.showDetail.rawValue, sender: self)     }     func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation ) -> MKAnnotationView? {         let identifier = "custompin"         guard !annotation.isKind(of: MKUserLocation.self) else {             return nil         }         var annotationView: MKAnnotationView?         if let customAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) {             annotationView = customAnnotationView             annotationView?.annotation = annotation         } else {             let av = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)             av.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)             annotationView = av         }         if let annotationView = annotationView {             annotationView.canShowCallout = true             annotationView.image = UIImage(named: "custom-annotation")         }         return annotationView     } } I am wondering if there is some action that I have not done previously that is causing these errors. Can anyone help?
Replies
1
Boosts
0
Views
787
Activity
Sep ’21
Could not cast value of type 'Swift.Array.
I am trying to learn Xcode using iOS 14 Programming for Beginners (Packt Pub). I am now working on the part that adds the pins to the MapView, but when I run the app the map button is unresponsive (Runtime error). I get the following message in the Debug area: __2021-07-25 16:08:23.919240+0100 EatOut[1420:21167] Metal API Validation Enabled Could not cast value of type 'Swift.Array<EatOut.RestaurantItem>' (0x1c31e3588) to '__C.MKAnnotation' (0x1c31e3888). 2021-07-25 16:08:24.003987+0100 EatOut[1420:21167] Could not cast value of type 'Swift.Array<EatOut.RestaurantItem>' (0x1c31e3588) to '__C.MKAnnotation' (0x1c31e3888). Could not cast value of type 'Swift.Array<EatOut.RestaurantItem>' (0x1c31e3588) to 'C.MKAnnotation' (0x1c31e3888). CoreSimulator 757.5 - Device: iPhone SE (2nd generation) (E06FF756-9D0E-45B8-BBF5-7B393524B880) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone SE (2nd generation) I'm sure that this message means a lot to you experts, but as a beginner I haven't a clue! The runtime error is in this func, in the final line:  func addMap(_ annontations: [RestaurantItem]) {             mapView.setRegion(manager.currentRegion(latDelta: 0.5, longDelta: 0.5), animated: true)             mapView.addAnnotation(manager.annotations as! MKAnnotation) I get a build error on the final line if I do not apply the fix, which adds the as! MKAnnotation. Is the error in the .plist or does the code need altering? Please can you help? Here is the full code for the swift file: //  MapViewController.swift //  EatOut // //  Created by Tony Hudson on 15/07/2021. // import UIKit import MapKit class MapViewController: UIViewController, MKMapViewDelegate {     let manager = MapDataManager()     var selectedRestaurant: RestaurantItem?     @IBOutlet weak var mapView: MKMapView!     override func viewDidLoad() {         initialise()         func initialise() {             manager.fetch { (annotations) in addMap(annotations)             }         }         func addMap(_ annontations: [RestaurantItem]) {             mapView.setRegion(manager.currentRegion(latDelta: 0.5, longDelta: 0.5), animated: true)             mapView.addAnnotation(manager.annotations as! MKAnnotation)         }     } }
Replies
2
Boosts
0
Views
1.2k
Activity
Jul ’21
Collection view not displaying Cells
I am trying to learn Xcode using iOS 14 Programming for Beginners. I have just entered the code to add the images and titles on the explore screen and have checked the code with the code written by the author and it is correct. When the Explore screen opens in the simulator it should show the images with titles on the screen. All that I get is the header at the top! I have checked the connection for the IBOutlets and the have the dot in the circle, so they are connected. The code builds OK, so I am not sure what is wrong? How can I find what is causing this problem? I have not mastered debugging yet, would this help? Here is the ExploreCell.swift //  ExploreCellCollectionViewCell.swift //  EatOut // //  Created by Tony Hudson on 02/06/2021. // import UIKit class ExploreCell: UICollectionViewCell {     @IBOutlet weak var lblName: UILabel!     @IBOutlet weak var imgExplore: UIImageView! } Here is ExploreItem.swift //  ExploreItem.swift //  EatOut // //  Created by Tony Hudson on 02/06/2021. // import Foundation struct  ExploreItem {     var name: String     var image: String }     extension ExploreItem {         init(dict: [String:AnyObject]) {             self.name = dict["name"] as! String             self.image = dict["image"] as! String         }     } Here is ExploreDataManager.swift //  ExploreDataManager.swift //  EatOut // //  Created by Tony Hudson on 02/06/2021. // import Foundation class ExploreDataManager {     fileprivate var items: [ExploreItem] = []     func fetch() {         for data in loadData() {             items.append(ExploreItem(dict: data))         }     }     fileprivate func loadData() -> [[String: AnyObject]] {         guard let path = Bundle.main.path(forResource: "ExploreData", ofType: "plist"), let items = NSArray(contentsOfFile: path) else {             return [[:]]         }         return items as! [[String: AnyObject]]     }     func numberOfItems() -> Int {         items.count     }     func explore(at index:IndexPath) -> ExploreItem {         items[index.item]     } } I think that is as much information that I can give! Can someone point me in the right direction so that I can solve this problem?
Replies
9
Boosts
0
Views
3.2k
Activity
Jul ’21
Connecting Navigation Controller to View controller
I am trying to learn Xcode using iOS 14 Programming for Beginners. I some how made an error when working through the instructions in the book. There are 2 navigation controllers and I connected a view controller to the wrong Navigation controller. When I realised my mistake I deleted the segue between the wrong Navigation Controller and the view controller. I then Ctrl + Dragged from the correct Nav Controller to the view controller and then created a new View Controller and did the same to this controller to the other Nav controller. If I build the app every thing seems to work, except the Nav controller does not load the Map view when I click on the map icon, even though I have added the Map View to the View Controller. Please help?
Replies
3
Boosts
0
Views
2.3k
Activity
May ’21
View Controller not visible in Identity Inspector
I am trying to learn Xcode using iOS 14 Programming for Beginners. I have just created a new View Controller and created a Cocoa Touch class called RestaurantListViewController. In this I had to add 2 collection view stubs and an @IBoutlet var to the UICollectionView. The book then instructs me to click on th View Controller in the document outline, for the view controller I have just created, the click on the Identity Inspector to add the class, but it says no selection? I can't see where I am going wrong? The only warning I get is: Prototype collection view cells must have reuse indentifiers. Here is the code for the class: // //  RestaurantListViewController.swift //  EatOut // //  Created by Tony Hudson on 22/05/2021. // import UIKit class RestaurantListViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {     @IBOutlet weak var collectionView: UICollectionView!     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.     }     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) - Int {         1     }     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) - UICollectionViewCell {       return collectionView.dequeueReusableCell(withReuseIdentifier: "restaurantCell", for: indexPath)     } } Please can someone help?
Replies
3
Boosts
0
Views
1.9k
Activity
May ’21
Cancel button not working?
I am learning to code using iOS 14 Programming for beginners. I was trying to place the Tab Bar buttons and confused the correct view in the scene. I was trying to add them to the Navigation Controller scene, but should have added them to the View controller scene. When I run the code the Cancel button should return to the previous scene, but does not. How do I get rid of the actions that I have made by trying to add the tab bar to the wrong scene, assuming that this is what is causing the button not to work? I have not added any code as I don't think that will serve any purpose at this stage.
Replies
2
Boosts
0
Views
1.7k
Activity
May ’21
"Invalid parameter not satisfying: [constraint isKindOfClass:[NSLayoutConstraint class]]"
I am learning Xcode from a book 'iOS Programming for Beginners' and although I am sure I entered the text correctly I get the following error when I click on the Location button. The code builds with out error, so I don't know where the error is! Here is the code: // //  LocationViewController.swift //  LetsEat3 // //  Created by Tony Hudson on 27/04/2021. // import UIKit class LocationViewController: UIViewController, UITableViewDataSource {     @IBOutlet weak var tableView: UITableView!     override func viewDidLoad() {         super.viewDidLoad()     }     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) - Int {         10     }     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell {         let cell = tableView.dequeueReusableCell(withIdentifier: "locationCell", for: indexPath)         cell.textLabel?.text = "A Cell"         return cell     } } cal=n anyone explain why I get this error?
Replies
4
Boosts
0
Views
3.9k
Activity
May ’21