Skip to content

Commit

Permalink
Merge pull request #11 from noblakit01/fixbug_url_tableviewcell
Browse files Browse the repository at this point in the history
Fixbug url tableviewcell
  • Loading branch information
noblakit01 authored Dec 16, 2017
2 parents ea8b8c0 + 5ed2edf commit e84e9b6
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
language: objective-c
osx_image: xcode8.3

before_install:
- pod repo update

script:
- xcodebuild build -workspace PhotoCollectionView.xcworkspace -scheme PhotoCollectionView -sdk iphonesimulator
- xcodebuild build -workspace PhotoCollectionView.xcworkspace -scheme PhotoCollectionViewDemo -sdk iphonesimulator
Expand Down
14 changes: 14 additions & 0 deletions PhotoCollectionView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,12 @@
TargetAttributes = {
0F3BD7441F1E5B870003A218 = {
CreatedOnToolsVersion = 8.3.2;
DevelopmentTeam = TMH6L6FX6W;
ProvisioningStyle = Automatic;
};
OBJ_16 = {
ProvisioningStyle = Manual;
};
};
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "PhotoCollectionView" */;
Expand Down Expand Up @@ -415,6 +419,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = TMH6L6FX6W;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -467,6 +472,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEVELOPMENT_TEAM = TMH6L6FX6W;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand All @@ -493,6 +499,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 8AFFE575DCA5992B0ABFF7F2 /* Pods-PhotoCollectionView.debug.xcconfig */;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -507,6 +516,7 @@
PRODUCT_BUNDLE_IDENTIFIER = PhotoCollectionView;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
TARGET_NAME = PhotoCollectionView;
};
Expand All @@ -516,6 +526,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = A59E36DFC3CD24C195800490 /* Pods-PhotoCollectionView.release.xcconfig */;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -530,6 +543,7 @@
PRODUCT_BUNDLE_IDENTIFIER = PhotoCollectionView;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
TARGET_NAME = PhotoCollectionView;
};
Expand Down
32 changes: 24 additions & 8 deletions PhotoCollectionViewDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -63,7 +63,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="1dJ-xe-Cmo">
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<rect key="frame" x="0.0" y="84" width="375" height="583"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" rowHeight="120" id="vFv-JW-Jae" customClass="TableViewCell" customModule="PhotoCollectionViewDemo" customModuleProvider="target">
Expand Down Expand Up @@ -145,27 +145,41 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="1zn-qJ-wxO">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="1zn-qJ-wxO">
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" rowHeight="120" id="xYg-hd-4T6" customClass="URLTableViewCell" customModule="PhotoCollectionViewDemo" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="120"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" rowHeight="180" id="xYg-hd-4T6" customClass="URLTableViewCell" customModule="PhotoCollectionViewDemo" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="180"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="xYg-hd-4T6" id="xfi-uh-vKJ">
<rect key="frame" x="0.0" y="0.0" width="375" height="119.5"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="179.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ot5-QN-aEC">
<rect key="frame" x="0.0" y="0.0" width="375" height="60"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mh1-2S-eKW">
<rect key="frame" x="12" y="20" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.14901960780000001" green="0.68235294120000001" blue="0.76078431369999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="60" id="ja5-b2-cQx"/>
<constraint firstItem="Mh1-2S-eKW" firstAttribute="leading" secondItem="ot5-QN-aEC" secondAttribute="leading" constant="12" id="Glx-RO-545"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="Mh1-2S-eKW" secondAttribute="trailing" constant="8" id="VU4-zM-xXV"/>
<constraint firstItem="Mh1-2S-eKW" firstAttribute="centerY" secondItem="ot5-QN-aEC" secondAttribute="centerY" id="iJh-9p-NsL"/>
<constraint firstAttribute="height" priority="750" constant="60" id="ja5-b2-cQx"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="AWL-7q-Ovo" customClass="PhotoCollectionView" customModule="PhotoCollectionView">
<rect key="frame" x="0.0" y="60" width="375" height="59.5"/>
<rect key="frame" x="0.0" y="60" width="375" height="120"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" priority="750" constant="120" id="UjT-b1-jdQ"/>
</constraints>
</view>
</subviews>
<constraints>
Expand All @@ -179,7 +193,9 @@
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="indexLabel" destination="Mh1-2S-eKW" id="CYQ-L0-CM4"/>
<outlet property="photoCollectionView" destination="AWL-7q-Ovo" id="AnJ-0B-ncM"/>
<outlet property="photoCollectionViewHeight" destination="UjT-b1-jdQ" id="nls-bx-SBx"/>
</connections>
</tableViewCell>
</prototypes>
Expand Down
23 changes: 18 additions & 5 deletions PhotoCollectionViewDemo/URLDemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class URLDemoViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

tableView.estimatedRowHeight = 200
tableView.rowHeight = UITableViewAutomaticDimension
tableView.tableFooterView = nil
}

Expand All @@ -48,8 +46,9 @@ extension URLDemoViewController: UITableViewDataSource {

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! URLTableViewCell
cell.urls = urls[indexPath.row]
cell.set(index: indexPath.row)
cell.photoCollectionView.delegate = self
cell.urls = urls[indexPath.row]
return cell
}

Expand All @@ -58,8 +57,22 @@ extension URLDemoViewController: UITableViewDataSource {
extension URLDemoViewController: PhotoCollectionViewDelegate {

func didChangeSize(of photoCollectionView: PhotoCollectionView) {
tableView.beginUpdates()
tableView.endUpdates()
update(height: photoCollectionView.intrinsicContentSize.height, at: photoCollectionView.tag)
}

func photoCollectionView(_ photoCollectionView: PhotoCollectionView, didCreated photoView: PhotoView, at index: Int) {
update(height: photoCollectionView.intrinsicContentSize.height, at: photoCollectionView.tag)
}

func update(height: CGFloat, at index: Int) {
let indexPath = IndexPath(item: index, section: 0)

if let cell = tableView.cellForRow(at: indexPath) as? URLTableViewCell {
cell.photoCollectionViewHeight.constant = height

tableView.beginUpdates()
tableView.endUpdates()
}
}

}
8 changes: 8 additions & 0 deletions PhotoCollectionViewDemo/URLTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import PhotoCollectionView
class URLTableViewCell: UITableViewCell {

@IBOutlet weak var photoCollectionView: PhotoCollectionView!
@IBOutlet weak var indexLabel: UILabel!
@IBOutlet weak var photoCollectionViewHeight: NSLayoutConstraint!

var urls: [String] = [] {
didSet {
if urls != oldValue {
photoCollectionView.reloadData()
photoCollectionViewHeight.constant = photoCollectionView.intrinsicContentSize.height
}
}
}
Expand All @@ -26,6 +29,11 @@ class URLTableViewCell: UITableViewCell {

photoCollectionView.dataSource = self
}

func set(index: Int) {
photoCollectionView.tag = index
indexLabel.text = "Cell \(index)"
}

}

Expand Down
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ target 'PhotoCollectionView' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!

pod 'SwiftyImageCache', '~> 1.2.0
pod 'SwiftyImageCache', '~> 1.2.1
end
target 'PhotoCollectionViewDemo' do
use_frameworks!
pod 'SwiftyImageCache', '~> 1.2.0
pod 'SwiftyImageCache', '~> 1.2.1

end
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PODS:
- SwiftyImageCache (1.1.1)
- SwiftyImageCache (1.2.1)

DEPENDENCIES:
- SwiftyImageCache (~> 1.1.1)
- SwiftyImageCache (~> 1.2.1)

SPEC CHECKSUMS:
SwiftyImageCache: da2bf80e02ebb05ceb4276b3810fe2b833e5cd99
SwiftyImageCache: 4c076f1f34503867fce19e7ff2c142f284ad67c3

PODFILE CHECKSUM: 89d6218d868798e680c5d5846d2c727b141df11b
PODFILE CHECKSUM: 395f7b683656c4f64577a7e45b0b721399dfae4a

COCOAPODS: 1.3.1
17 changes: 8 additions & 9 deletions Sources/PhotoCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import SwiftyImageCache

@objc public protocol PhotoCollectionViewDataSource: NSObjectProtocol {
func numPhotos(in photoCollectionView: PhotoCollectionView) -> Int
Expand Down Expand Up @@ -35,13 +36,7 @@ open class PhotoCollectionView: UIView {
open var moreTextFont: UIFont! = UIFont.systemFont(ofSize: 17)

var layout: PhotoLayoutProtocol!

override open var bounds: CGRect {
didSet {
reloadData()
}
}


override open var intrinsicContentSize: CGSize {
return layout != nil ? layout.contentSize(of: self) : bounds.size
}
Expand Down Expand Up @@ -88,8 +83,13 @@ open class PhotoCollectionView: UIView {
layout = layoutFor(numImage: numImage)
let numShow = min(layout.maxPhoto, numImage)
for i in 0..<numShow {
let image = dataSource.photoCollectionView?(self, imageAt: i)
var image = dataSource.photoCollectionView?(self, imageAt: i)
let url = dataSource.photoCollectionView?(self, urlImageAt: i)
if image == nil,
let url = url,
let cacheImage = ImageCache.default.image(of: url) {
image = cacheImage
}
images.append(image)
urls.append(url?.absoluteString)

Expand Down Expand Up @@ -133,7 +133,6 @@ open class PhotoCollectionView: UIView {
for (index, photoView) in photoViews.enumerated() {
photoView.frame = layout.frame(at: index, in: self)
}
invalidateIntrinsicContentSize()
delegate?.didChangeSize?(of: self)
}

Expand Down

0 comments on commit e84e9b6

Please sign in to comment.