Kodeco Forums

Storyboards Tutorial in iOS 9: Part 2

Learn about segues and more table view customization in the final part of this Storyboards tutorial, fully up-to-date for iOS 9.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1565-storyboards-tutorial-in-ios-9-part-2

Hi Caroline,
detailLabel.text? = game
is giving me an error saying that UIView has no text property.

@sg14_96 - UILabel does though :wink:.

Selecting the label fields when you are creating an outlet from a cell is a bit tricky.

In the tutorial I tried to convey this by:

You might need to click a few times on the text “Detail” to select the label (and not the whole cell) before ctrl-clicking and dragging to PlayerDetailsViewController.swift. Once done, it will look something like this:

Image from tutorial

Check that detailLabel is actually a UILabel and connected to the right field in the storyboard.

Hey Caroline,
I fixed the label stuff but it wasn’t saving the selected game.
I then realized I forgot to set the unwind segue identifier to “SaveSelectedGame” in the story board.
Thanks so much for your help, the app works perfectly!

1 Like

Hi, first I’d like to say great tutorial. I have everything mentioned in the tutorial working but would like to know how can I update the code so I when an game item is selected, to doesn’t unwind automatically by going back to the player view. I would have to click the back button to return to the previous view but the selected field still shows on the game row in the player view. Similar to the iphone setting where when you select an option field but doesn’t go back to the previous view until you select the back button. Please advise.

Thanks

@met
Delete the unwind segue from Game Scene

I think I might create a delegate to transfer the information. Something like:

protocol GamePickerViewControllerDelegate {
  func didSelectGame(game: String)
}

In GamePickerViewController:

var gameDelegate: GamePickerViewControllerDelegate?

var selectedGame:String? {
  didSet {
    if let game = selectedGame {
      selectedGameIndex = games.indexOf(game)!
      gameDelegate?.didSelectGame(game)
    }
  }
}

In PlayerDetailsViewController:

in prepareForSegue:

    gamePickerViewController.gameDelegate = self

and

extension PlayerDetailsViewController: GamePickerViewControllerDelegate {
  func didSelectGame(game: String) {
    self.game = game
  }
}

Thanks I will try it out in the morning, and get to back to you. Thanks for replying back to so quickly.

Thanks it worked perfectly.

Hard to follow the moves for a beginner like me. Not the code, but the flow, like changing of attributes which I can’t see in my editor.

Hi There,

I followed your tutorial and did everything as you instructed. However I changed it in a way that there is no field to pick a game when adding a new player but a second text field. Everything went great, I don’t see any errors when compiling and running the code. My problem is that when I write something to those fields and click “Done” I get to my tableview but nothing gets added to the table. Any idea what might be the reason? I did table updating with animations as you instructed. Everything is as you instructed except that Game picking option.

Thanks in advance.

@iikkamovitsh - no, I don’t know what the reason is.

But you can track it down using print() statements.

The first place I would try is in PlayersViewController in savePlayerDetail(_:). That’s where the save takes place. Check that the method is called on the exit segue.

Thanks for your reply Caroline.

I finally found my failure: I hadn’t given an Identifier to my Unwind segue method for Done button. Feeling a bit stupid at the moment :smiley:

1 Like

Hello great tutorial. I am having difficulty following this and making the conversion to Xcode 8.2.1. My difficultly starts in savePlayerDetail: and was wondering have you compiled this in version 8.2.1 and can you make it available?

Thanks again.

Hi @wh99810

I just downloaded the sample code, and converted it to Swift 3, Xcode 8.2.1

If you have problems converting, try this. Download the zip file. On first open, when it asks you to convert, click Later (twice). In project settings, change the developer team to yours, and close the project.

When you open the project, do the Convert, and it should convert fine and succeed in building.

I attach the version I just did this with, so I hope that will help.

Ratings-Xcode 8.2.zip (140.3 KB)