Skip to content

Commit

Permalink
Merge pull request #24 from nghialv/swift2.0
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
nghialv committed Mar 4, 2016
2 parents af1f77b + ea46712 commit 8924c14
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
18 changes: 6 additions & 12 deletions Example/MYTableViewManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -387,7 +387,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand All @@ -399,7 +399,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = MYTableViewManager/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -410,7 +410,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = MYTableViewManager/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -420,10 +420,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -439,10 +436,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = MYTableViewManagerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
7 changes: 4 additions & 3 deletions Example/MYTableViewManager/CustomCell.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand All @@ -11,9 +11,10 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="53"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Yg9-fY-9K6" id="Nkn-4U-4HG">
<rect key="frame" x="0.0" y="0.0" width="320" height="53"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1Yt-G9-XLh" customClass="MYLabel" customModule="MYTableViewManager" customModuleProvider="target">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="0.0" translatesAutoresizingMaskIntoConstraints="NO" id="1Yt-G9-XLh" customClass="MYLabel" customModule="MYTableViewManager" customModuleProvider="target">
<rect key="frame" x="16" y="12" width="288" height="29"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
Expand Down
9 changes: 9 additions & 0 deletions Source/Hakuba.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class Hakuba : NSObject {
tableView.dataSource = self
}

deinit {
tableView?.delegate = nil
tableView?.dataSource = nil
}

public func deselectAllCells() {
for cell in selectedCells {
if let cellmodel = (cell as? MYTableViewCell)?.cellModel {
Expand Down Expand Up @@ -206,6 +211,10 @@ extension Hakuba : MYViewModelDelegate {
}
}
}

public func deselectRow(indexPath: NSIndexPath, animated: Bool) {
tableView?.deselectRowAtIndexPath(indexPath, animated: animated)
}
}

// MARK - UITableViewDelegate
Expand Down
12 changes: 8 additions & 4 deletions Source/MYTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import UIKit

public class MYCellModel : MYViewModel {
let identifier: String
internal(set) var row: Int = 0
internal(set) var section: Int = 0
var indexPath: NSIndexPath {
public internal(set) var row: Int = 0
public internal(set) var section: Int = 0
public var indexPath: NSIndexPath {
return NSIndexPath(forRow: row, inSection: section)
}
var calculatedHeight: CGFloat?
Expand All @@ -35,11 +35,15 @@ public class MYCellModel : MYViewModel {
delegate?.reloadView(row, section: section, animation: animation)
return self
}

public func deselect(animated: Bool) {
delegate?.deselectRow(indexPath, animated: animated)
}
}

public class MYTableViewCell : UITableViewCell, MYBaseViewProtocol {
private weak var delegate: MYBaseViewDelegate?
public internal(set) weak var cellModel: MYCellModel?
public private(set) weak var cellModel: MYCellModel?

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand Down
1 change: 1 addition & 0 deletions Source/MYViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public protocol MYViewModelDelegate : class {
func reloadView(index: Int, section: Int, animation: MYAnimation)
func reloadHeader(section: Int)
func reloadFooter(section: Int)
func deselectRow(indexPath: NSIndexPath, animated: Bool)
}

public class MYViewModel : NSObject, MYBaseViewDelegate {
Expand Down

0 comments on commit 8924c14

Please sign in to comment.