Created
March 21, 2016 14:22
-
-
Save takasek/fd0016b7d90492007627 to your computer and use it in GitHub Desktop.
TableViewCellとそのデータを複数パターン用意したい場合は、cellForRowAtIndexPathでswitch使うのが便利だと思う #CodePiece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
switch (tableView.dequeueReusableCellWithIdentifier("cardCell", forIndexPath: indexPath), hand[indexPath.row]) { | |
case (let cell as? CardCell, let data as? Card): | |
cell.fillWith(data) | |
case (let cell as? HogeCell, let data as? Hoge): | |
cell.fillWith(data) | |
case (let cell as? FugaCell, let data as? Fuga): | |
cell.fillWith(data) | |
default: | |
fatalError("Could not create any Cell") | |
} | |
return cell | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment