Displaying data in a table view using LocationDataManager

Currently, LocationViewController gets a list of locations from the locations array. In this section, you will update LocationViewController so that it uses LocationDataManager instead. Follow these steps to do so:

  1. You won't need the locations array anymore, so delete the following code:
let locations = ["Aspen", "Boston", "Charleston", "Chicago", 
"Houston", "Las Vegas", "Los Angeles",
"Miami", "New Orleans", "New York",
"Philadelphia", "Portland", "San Antonio",
"San Francisco",
"Washington District of Columbia"]
  1. Next, create an instance of LocationDataManager by typing the following property declaration before the viewDidLoad() method:
let manager = LocationDataManager()
  1. Inside viewDidLoad(), fetch the data for the table view by adding the following under super.viewDidLoad():
manager.fetch()

viewDidLoad() should look as follows:

override func viewDidLoad() {
super.viewDidLoad()
manager.fetch()
}
  1. Modify tableView(_:numberOfRowsInSection:) like so:
func tableView(_ tableView: UITableView, numberOfRowsInSection 
section: Int) -> Int{
manager.numberOfItems()
}
  1. Modify tableView(_:cellForRowAt:) like so:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: 
IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:
"locationCell", for: indexPath) as UITableViewCell
cell.textLabel?.text = manager.locationItem(at:indexPath)
return cell
}

Build and run your app. You should still see the locations in table view, but now they should be coming from ExploreData.plist. Great!

If you compare your app's Explore and Locations screens to the screens shown in the app tour, you'll notice some user interface issues. The text in the Locations screens is too small, and the labels at the top of the Explore screen just say Label. You need to make the table view text larger so that it will be easier to read, and modify the labels at the top of the Explore screen so that the subtitle displays PLEASE SELECT A LOCATION and the title displays EXPLORE, as shown in the app tour. You'll do this in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.105.239