Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Multiple layout with UITableViewCell

yashigani
November 30, 2015

Multiple layout with UITableViewCell

関モバ #8

yashigani

November 30, 2015
Tweet

More Decks by yashigani

Other Decks in Programming

Transcript

  1. • Pros • ΍Δ͜ͱࣗମ͸୯७ • Cons • ফ͑ΔView໰୊ • Auto

    Layoutͷઃఆ͕೉͍͠ • ϨΠΞ΢τͷશ༰Λ௫Έʹ͍͘
  2. class EntryCell: UITableViewCell { @IBOutlet weak var titleLabel: UILabel! @IBOutlet

    weak var thumbnailView:UIImageView? var entry: Entry! }
  3. protocol EntryCellRepresentable { var tableView: UITableView! { get } func

    registerEntryCell() func dequeueEntryCell(entry: Entry, forIndexPath indexPath: NSIndexPath) -> EntryCell }
  4. extension EntryCellRepresentable { func registerEntryCell() { let ids = ["EntryCell",

    "EntryCellWithImage"] ids.forEach { let nib = UINib(nibName: $0, bundle: nil) tableView.registerNib(nib, forCellReuseIdentifier: $0) } } func dequeueEntryCell(entry: Entry, forIndexPath
 indexPath: NSIndexPath) -> EntryCell { let id = entry.hasImage ? "EntryCellWithImage" : "EntryCell" let cell =
 tableView.dequeueReusableCellWithIdentifier(id,
 forIndexPath: indexPath) as! EntryCell cell.entry = entry return cell } }