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. .VMUJQMFMBZPVUXJUI 6*5BCMF7JFX$FMM @yashigani ؔϞό #8

  2. yashigani id:yashigani_w @yashigani Mobile Application Engineer http://yashigani.hatenablog.com Hatena

  3. None
  4. ͋Δ೔ͷͰ͖͝ͱ

  5. None
  6. None
  7. ඍົʹҧ͏ʜ

  8. ͍͔ʹͯ͠ෳ਺ͷ
 ϨΠΞ΢τΛ࣮ݱ͢Δ͔

  9. • ίʔυͰϨΠΞ΢τΛ͍͡Δ • xibΛෳ਺༻ҙͯ͠࢖͍෼͚Δ

  10. ίʔυͰ͍͡Δ࡞ઓ

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

    Layoutͷઃఆ͕೉͍͠ • ϨΠΞ΢τͷશ༰Λ௫Έʹ͍͘
  12. ෳ਺ͷYJCΛ࢖͏࡞ઓ

  13. • Pros • NSLayoutConstraintΛϓϩύςΟʹ͠ͳͯ͘Α͍ • Auto LayoutͷࢦఆΛ୯७ʹͰ͖Δ • viewࣗମͷϓϩύςΟΛ࢖͍෼͚Ͱ͖Δ •

    Cons • ෳ਺ͷxibΛϝϯςφϯε͢Δඞཁ͕͋Δ • ܾΊࣄ͕૿͑Δ(࢖͍ճ͠ʹ͘͞)
  14. ࣮૷ύλʔϯ

  15. class EntryCell: UITableViewCell { @IBOutlet weak var titleLabel: UILabel! @IBOutlet

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

    registerEntryCell() func dequeueEntryCell(entry: Entry, forIndexPath indexPath: NSIndexPath) -> EntryCell }
  17. 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 } }
  18. ·ͱΊ

  19. • xibΛ෼͚ΔͱAuto LayoutҎ֎΋࢖͍෼͚Ͱ͖Δ • OptionalΛ্खʹ࢖͓͏ • protocol extension࠷ߴ • UIStackViewૣ͘࢖ΘͤΖ

  20. ͋Γ͕ͱ͏͍͟͝·ͨ͠