Skip to content

Commit

Permalink
Fixed issue where tableViewCell and collectionViewCell are nil (#16)
Browse files Browse the repository at this point in the history
* Added variables and explanation

* Fixed cells always nil
  • Loading branch information
MaherKSantina authored Sep 11, 2018
1 parent c9f4026 commit 3eb101b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
14 changes: 5 additions & 9 deletions MSAutoView/Classes/MSCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

open class MSCollectionViewCell<T: UIView>: UICollectionViewCell {
open class MSCollectionViewCell<T: MSAutoView>: UICollectionViewCell {
public var mainView = T()

override init(frame: CGRect) {
Expand All @@ -24,25 +24,21 @@ open class MSCollectionViewCell<T: UIView>: UICollectionViewCell {
mainView.removeFromSuperview()
contentView.addSubviewWithConstraints(mainView)
backgroundColor = mainView.backgroundColor
mainView.collectionViewCell = self
}
}

public protocol CollectionViewCellContainable {
associatedtype CollectionViewCellContainedViewType: UIView
associatedtype CollectionViewCellContainedViewType: MSAutoView

var collectionViewCell: MSCollectionViewCell<CollectionViewCellContainedViewType> { get }
static var collectionViewCell: MSCollectionViewCell<CollectionViewCellContainedViewType>.Type { get }
}

extension CollectionViewCellContainable where Self: UIView {

public var collectionViewCell: MSCollectionViewCell<Self> {
return MSCollectionViewCell()
}
extension CollectionViewCellContainable where Self: MSAutoView {

public static var collectionViewCell: MSCollectionViewCell<Self>.Type {
return MSCollectionViewCell<Self>.self
}
}

extension UIView: CollectionViewCellContainable { }
extension MSAutoView: CollectionViewCellContainable { }
14 changes: 5 additions & 9 deletions MSAutoView/Classes/MSTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

open class MSTableViewCell<T: UIView>: UITableViewCell {
open class MSTableViewCell<T: MSAutoView>: UITableViewCell {

public var mainView = T()

Expand All @@ -25,26 +25,22 @@ open class MSTableViewCell<T: UIView>: UITableViewCell {
mainView.removeFromSuperview()
contentView.addSubviewWithConstraints(mainView)
backgroundColor = mainView.backgroundColor
mainView.tableViewCell = self
}
}


public protocol TableViewCellContainable {
associatedtype TableViewCellContainedViewType: UIView
associatedtype TableViewCellContainedViewType: MSAutoView

var tableViewCell: MSTableViewCell<TableViewCellContainedViewType> { get }
static var tableViewCell: MSTableViewCell<TableViewCellContainedViewType>.Type { get }
}

extension TableViewCellContainable where Self: UIView {

public var tableViewCell: MSTableViewCell<Self> {
return MSTableViewCell()
}
extension TableViewCellContainable where Self: MSAutoView {

public static var tableViewCell: MSTableViewCell<Self>.Type {
return MSTableViewCell<Self>.self
}
}

extension UIView: TableViewCellContainable { }
extension MSAutoView: TableViewCellContainable { }

0 comments on commit 3eb101b

Please sign in to comment.