Permalink
Browse files

refactored table view cell nib loading and dequing

  • Loading branch information...
NatashaTheRobot committed Sep 20, 2016
1 parent 85f86d9 commit 70e950687cb2bc13e6713ae015612246fb96c7d2
@@ -79,6 +79,9 @@
FA65B5C21C79BE1D00DCAF0B /* Session.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA65B5C11C79BE1D00DCAF0B /* Session.swift */; };
FA65B5C51C79C9BF00DCAF0B /* Speaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA65B5C41C79C9BF00DCAF0B /* Speaker.swift */; };
FA65B5C71C79C9E200DCAF0B /* Presentation.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA65B5C61C79C9E200DCAF0B /* Presentation.swift */; };
FAA54F101D912FF300EC9E80 /* ReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA54F0F1D912FF300EC9E80 /* ReusableView.swift */; };
FAA54F121D91305200EC9E80 /* NibLoadableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA54F111D91305200EC9E80 /* NibLoadableView.swift */; };
FAA54F141D9130F900EC9E80 /* UITableViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA54F131D9130F900EC9E80 /* UITableViewExtension.swift */; };
FABA73BE1D6D9ABB0081D887 /* OfficeHoursDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FABA73BD1D6D9ABB0081D887 /* OfficeHoursDetailViewController.swift */; };
FAC936E41D68F2CE00E2D6B0 /* ChangeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC936E31D68F2CE00E2D6B0 /* ChangeManager.swift */; };
FAED14CB1C7C1A1000F11E25 /* SessionTableRowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAED14CA1C7C1A1000F11E25 /* SessionTableRowController.swift */; };
@@ -245,6 +248,9 @@
FA65B5C11C79BE1D00DCAF0B /* Session.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Session.swift; sourceTree = "<group>"; };
FA65B5C41C79C9BF00DCAF0B /* Speaker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Speaker.swift; sourceTree = "<group>"; };
FA65B5C61C79C9E200DCAF0B /* Presentation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Presentation.swift; sourceTree = "<group>"; };
FAA54F0F1D912FF300EC9E80 /* ReusableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReusableView.swift; sourceTree = "<group>"; };
FAA54F111D91305200EC9E80 /* NibLoadableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibLoadableView.swift; sourceTree = "<group>"; };
FAA54F131D9130F900EC9E80 /* UITableViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewExtension.swift; sourceTree = "<group>"; };
FABA73BD1D6D9ABB0081D887 /* OfficeHoursDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OfficeHoursDetailViewController.swift; sourceTree = "<group>"; };
FAC936E31D68F2CE00E2D6B0 /* ChangeManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangeManager.swift; sourceTree = "<group>"; };
FAED14CA1C7C1A1000F11E25 /* SessionTableRowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionTableRowController.swift; sourceTree = "<group>"; };
@@ -399,6 +405,8 @@
FAF1DE171D5FDD3B00D710C3 /* VenueHeaderTableViewCell */,
FAF1DE1C1D5FE15200D710C3 /* MapTableViewCell */,
FA20176C1D69D81B00B6E158 /* WifiInfoTableViewCell */,
FAA54F0F1D912FF300EC9E80 /* ReusableView.swift */,
FAA54F111D91305200EC9E80 /* NibLoadableView.swift */,
);
name = Views;
sourceTree = "<group>";
@@ -411,6 +419,7 @@
FA65B5941C7274EE00DCAF0B /* UIImageExtension.swift */,
499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */,
FA3A1CB51D68E1950042F8DD /* WatchSessionManager.swift */,
FAA54F131D9130F900EC9E80 /* UITableViewExtension.swift */,
);
name = Utilities;
sourceTree = "<group>";
@@ -1056,6 +1065,7 @@
499BD62A1D05910200E74061 /* Twitter.swift in Sources */,
FA39E90F1C6C81870074B6BE /* SponsorsViewController.swift in Sources */,
FA39E8D71C6B05980074B6BE /* Session.swift in Sources */,
FAA54F141D9130F900EC9E80 /* UITableViewExtension.swift in Sources */,
FABA73BE1D6D9ABB0081D887 /* OfficeHoursDetailViewController.swift in Sources */,
FAF1DE151D5FDD3700D710C3 /* VenueHeaderTableViewCell.swift in Sources */,
FA39E92C1C6D310E0074B6BE /* TwitterFollowTableViewCell.swift in Sources */,
@@ -1068,11 +1078,13 @@
FA65B58A1C6D8A5200DCAF0B /* OrganizersTableViewController.swift in Sources */,
FAF1DE1A1D5FE14500D710C3 /* MapTableViewCell.swift in Sources */,
FA39E91D1C6C8D100074B6BE /* WebDisplayViewController.swift in Sources */,
FAA54F101D912FF300EC9E80 /* ReusableView.swift in Sources */,
FAFA15BC1C69D31C00FEA4EA /* AppDelegate.swift in Sources */,
FA39E8DD1C6B09DF0074B6BE /* Sponsor.swift in Sources */,
FA65B5801C6D7B1900DCAF0B /* MoreTableViewController.swift in Sources */,
FA20176A1D69D81600B6E158 /* WifiInfoTableViewCell.swift in Sources */,
FA39E9161C6C83A40074B6BE /* SponsorTableViewCell.swift in Sources */,
FAA54F121D91305200EC9E80 /* NibLoadableView.swift in Sources */,
FAF1DE2D1D623B2C00D710C3 /* Venue.swift in Sources */,
FA39E8DB1C6B09CE0074B6BE /* Speaker.swift in Sources */,
FA65B5951C7274EE00DCAF0B /* UIImageExtension.swift in Sources */,
@@ -18,16 +18,8 @@ class AboutTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "About"
tableView.register(UINib(nibName: String(describing: OrganizerTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: OrganizerTableViewCell.self))
tableView.register(UINib(nibName: String(describing: TextTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: TextTableViewCell.self))
tableView.register(UINib(nibName: String(describing: TwitterFollowTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: TwitterFollowTableViewCell.self))
tableView.estimatedRowHeight = 83
tableView.rowHeight = UITableViewAutomaticDimension
tableView.separatorStyle = .none
configureTableView()
}
}
@@ -43,22 +35,34 @@ extension AboutTableViewController {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch AboutInfo(rawValue: (indexPath as NSIndexPath).row)! {
switch AboutInfo(rawValue: (indexPath as IndexPath).row)! {
case .header:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: OrganizerTableViewCell.self), for: indexPath) as! OrganizerTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as OrganizerTableViewCell
cell.configure(withConference: trySwift)
cell.selectionStyle = .none
cell.accessoryType = .none
return cell
case .detail:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TextTableViewCell.self), for: indexPath) as! TextTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell
cell.configure(withText: trySwift.description)
return cell
case .twitter:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TwitterFollowTableViewCell.self), for: indexPath) as! TwitterFollowTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TwitterFollowTableViewCell
cell.configure(withUsername: trySwift.twitter, delegate: self)
return cell
}
}
}
fileprivate extension AboutTableViewController {
func configureTableView() {
tableView.register(OrganizerTableViewCell.self)
tableView.register(TextTableViewCell.self)
tableView.register(TwitterFollowTableViewCell.self)
tableView.estimatedRowHeight = 83
tableView.rowHeight = UITableViewAutomaticDimension
tableView.separatorStyle = .none
}
}
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -11,12 +12,11 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4bA-d3-zGi">
<rect key="frame" x="19" y="10" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="4bA-d3-zGi" secondAttribute="centerX" id="kcH-EZ-rRx"/>
<constraint firstAttribute="centerY" secondItem="4bA-d3-zGi" secondAttribute="centerY" id="lcE-iT-kgq"/>
@@ -0,0 +1,19 @@
//
// NibLoadableView.swift
// trySwift
//
// Created by Natasha Murashev on 9/20/16.
// Copyright © 2016 NatashaTheRobot. All rights reserved.
//
protocol NibLoadableView: class { }
extension NibLoadableView where Self: UIView {
static var nibName: String {
return String(describing: self)
}
}
extension UITableViewCell: NibLoadableView { }
@@ -40,19 +40,19 @@ extension OfficeHoursDetailViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch OfficeHoursDetail(rawValue: (indexPath as NSIndexPath).row)! {
case .header:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SessionHeaderTableViewCell.self), for: indexPath) as! SessionHeaderTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SessionHeaderTableViewCell
cell.configure(withSession: session)
return cell
case .speakerInfo:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SpeakerTableViewCell.self), for: indexPath) as! SpeakerTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false)
return cell
case .bio:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TextTableViewCell.self), for: indexPath) as! TextTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell
cell.configure(withText: speaker.bio)
return cell
case .twitter:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TwitterFollowTableViewCell.self), for: indexPath) as! TwitterFollowTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TwitterFollowTableViewCell
cell.configure(withUsername: speaker.twitter, delegate: self)
return cell
}
@@ -63,10 +63,10 @@ extension OfficeHoursDetailViewController {
extension OfficeHoursDetailViewController {
func configureTableView() {
tableView.register(UINib(nibName: String(describing: SessionHeaderTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: SessionHeaderTableViewCell.self))
tableView.register(UINib(nibName: String(describing: SpeakerTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: SpeakerTableViewCell.self))
tableView.register(UINib(nibName: String(describing: TextTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: TextTableViewCell.self))
tableView.register(UINib(nibName: String(describing: TwitterFollowTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: TwitterFollowTableViewCell.self))
tableView.register(SessionHeaderTableViewCell.self)
tableView.register(SpeakerTableViewCell.self)
tableView.register(TextTableViewCell.self)
tableView.register(TwitterFollowTableViewCell.self)
tableView.estimatedRowHeight = 83
tableView.rowHeight = UITableViewAutomaticDimension
@@ -21,9 +21,9 @@ class OrganizerDetailTableViewController: UITableViewController {
title = organizer.name
tableView.register(UINib(nibName: String(describing: OrganizerTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: OrganizerTableViewCell.self))
tableView.register(UINib(nibName: String(describing: TextTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: TextTableViewCell.self))
tableView.register(UINib(nibName: String(describing: TwitterFollowTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: TwitterFollowTableViewCell.self))
tableView.register(OrganizerTableViewCell.self)
tableView.register(TextTableViewCell.self)
tableView.register(TwitterFollowTableViewCell.self)
tableView.estimatedRowHeight = 83
tableView.rowHeight = UITableViewAutomaticDimension
@@ -45,15 +45,15 @@ extension OrganizerDetailTableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch OrganizerDetail(rawValue: (indexPath as NSIndexPath).row)! {
case .header:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: OrganizerTableViewCell.self), for: indexPath) as! OrganizerTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as OrganizerTableViewCell
cell.configure(withOrganizer: organizer, selectionEnabled: false, accessoryEnabled: false)
return cell
case .bio:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TextTableViewCell.self), for: indexPath) as! TextTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell
cell.configure(withText: organizer.bio)
return cell
case .twitter:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TwitterFollowTableViewCell.self), for: indexPath) as! TwitterFollowTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TwitterFollowTableViewCell
cell.configure(withUsername: organizer.twitter, delegate: self)
return cell
}
@@ -16,10 +16,7 @@ class OrganizersTableViewController: UITableViewController {
super.viewDidLoad()
title = "Organizer"
tableView.register(UINib(nibName: String(describing: OrganizerTableViewCell.self), bundle: nil), forCellReuseIdentifier: String(describing: OrganizerTableViewCell.self))
tableView.estimatedRowHeight = 83
tableView.rowHeight = UITableViewAutomaticDimension
configureTableView()
}
}
@@ -35,7 +32,7 @@ extension OrganizersTableViewController {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: OrganizerTableViewCell.self), for: indexPath) as! OrganizerTableViewCell
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as OrganizerTableViewCell
cell.configure(withOrganizer: organizers[(indexPath as NSIndexPath).row])
@@ -49,3 +46,12 @@ extension OrganizersTableViewController {
tableView.deselectRow(at: indexPath, animated: true)
}
}
fileprivate extension OrganizersTableViewController {
func configureTableView() {
tableView.register(OrganizerTableViewCell.self)
tableView.estimatedRowHeight = 83
tableView.rowHeight = UITableViewAutomaticDimension
}
}
@@ -0,0 +1,21 @@
//
// ReusableView.swift
// trySwift
//
// Created by Natasha Murashev on 9/20/16.
// Copyright © 2016 NatashaTheRobot. All rights reserved.
//
protocol ReusableView: class {}
extension ReusableView where Self: UIView {
static var reuseIdentifier: String {
return String(describing: self)
}
}
extension UITableViewCell: ReusableView { }
Oops, something went wrong.

3 comments on commit 70e9506

@BasThomas

This comment has been minimized.

Collaborator

BasThomas replied Sep 20, 2016

I didn't know this worked, nice!

@NatashaTheRobot

This comment has been minimized.

Contributor

NatashaTheRobot replied Sep 20, 2016

Yeah - should have done it earlier, but was lazy and now it caught up to me!

@sunshineLixun

This comment has been minimized.

sunshineLixun replied Dec 23, 2016

nice!

Please sign in to comment.