reloading visible uicollectionviewcell when nested in uitableviewcell - ios

I have a UICollection that shows a padlock on cells that locked to users who aren't logged in. The user can view the collection and then login in a modal. When the modal dismisses, I am trying to reload the cells of the table and the nested collection to remove the padlocks from the cells.
The visible cells are not refreshing to remove the padlock. When the collection is scrolled, the cells offscreen are correct and show with padlock. I am calling reloaddata() on both the tableview and each nested collectionview.
The code I have is separated to:
UIViewController
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("SectionWorkouts", forIndexPath: indexPath) as! SectionTableViewCell
cell.delegate = self
// Return the workouts count from the section
let intIndex = indexPath.row
let index = workoutSections.startIndex.advancedBy(intIndex)
let currentWorkoutSectionKey = workoutSections.keys[index]
if let currentWorkoutSection = workoutSections[currentWorkoutSectionKey] {
cell.workoutsCollection.dataSource = sectionWorkoutsCell
cell.workoutsCollection.delegate = sectionWorkoutsCell
cell.updateCellWithWorkouts(currentWorkoutSectionKey, workouts: currentWorkoutSection)
}
}
return cell
}
UITableViewCell
class SectionTableViewCell: UITableViewCell,UICollectionViewDelegate, UICollectionViewDataSource {
var workouts = [Workout]()
var delegate: WorkoutCellDelegate?
#IBOutlet weak var sectionTitle: UILabel!
#IBOutlet weak var workoutsCollection: UICollectionView!
func updateCellWithWorkouts(title: String, workouts: [Workout]){
self.sectionTitle.text = title
self.workouts = workouts
dispatch_async(dispatch_get_main_queue(),{
self.workoutsCollection.reloadData()
})
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("SectionWorkoutCell", forIndexPath: indexPath) as! SectionCollectionViewCell
let row = indexPath.row
let workout = workouts[row]
cell.configCell(workout)
return cell
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return workouts.count
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let row = indexPath.row
let feature = workouts[row]
if let delegate = self.delegate{
delegate.didSelectWorkoutCell(feature)
}
}
}
UICollectionViewCell
class SectionCollectionViewCell: UICollectionViewCell {
#IBOutlet weak var imageContainer: UIView!
#IBOutlet weak var image: UIImageView!
#IBOutlet weak var tintOverlay: UIView!
#IBOutlet weak var padlock: UIImageView!
#IBOutlet weak var workoutTitle: UILabel!
#IBOutlet weak var duration: UILabel!
var locked = true
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func configCell(workout: Workout){
self.workoutTitle.text = workout.name
if workout.type == "Free" || AccountManager.userIsLoggedInMember() {
self.setToUnLocked()
}else{
self.setToLocked()
}
self.layoutIfNeeded()
}
func setToUnLocked(){
locked = false
tintOverlay.alpha = 0
padlock.alpha = 0
}
func setToLocked(){
locked = true
tintOverlay.alpha = 0.6
padlock.alpha = 1
}
}

You should probably move the call to configure the cell to the willDisplayCell: method instead. You can remove it from the cellForItemAtIndexPath method. This is the correct time to configure any visual aspects of the cell to be displayed.
func collectionView(collectionView: UICollectionView,
willDisplayCell cell: UICollectionViewCell,
forItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let row = indexPath.row
let workout = workouts[row]
cell.configCell(workout)
return cell
}

The problem lies in the fact that:
the tableViewCell owns the data that is used for configuring the collectionViewCell.
If you want your collectionViewCell to update without the need for tableView.reloadData, the data that is used for configuring the collectionViewCell(in your case 'workout') must be fetched from elsewhere than from the tableViewCell.

Related

Reach CollectionViewCell into Xib with Programatically

I created a Xib File and call in ViewController.Also I create a CollectionView into Xib File.And now I want to reach CollectionViewCell for showing cells.
class ProductVC: UIViewController {
var collection:UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
let productView : ProductDetailView = UIView.fromNib()
productView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(productView)
collection = productView.collectionView
collection.register(UINib(nibName: "TagCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "TagCollectionViewCell")
productView.topAnchor.constraint(equalTo: view.safeTopAnchor).isActive = true
productView.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width).isActive = true
productView.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.height).isActive = true
}
}
class ProductDetailView: UIView {
#IBOutlet var productTitle: UILabel!
#IBOutlet var dateLabel: UILabel!
#IBOutlet var productImage: UIImageView!
#IBOutlet var productDescriptionLabel: UILabel!
#IBOutlet var collectionView: UICollectionView!
}
class TagCollectionViewCell: UICollectionViewCell {
#IBOutlet var tagName: UILabel!
}
Also I added some code like below . But has no sense!. Where is my mistake?
extension ProductVC : UICollectionViewDelegate , UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var cell: TagCollectionViewCell! = collectionView.dequeueReusableCell(withReuseIdentifier: "TagCollectionViewCell", for: indexPath) as? TagCollectionViewCell
if cell == nil {
collectionView.register(UINib(nibName: "TagCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "TagCollectionViewCell")
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagCollectionViewCell", for: indexPath) as? TagCollectionViewCell
}
cell.tagName.text = "aa"
return cell
}
}
You did not conform to delegate and dataSource protocols. I think this the problem. Put below lines after collection.register
collection.delegate = self
collection.dataSource = self
Hope this will work.

Reuse item inside a row when scrolling

I have collectionView inside tableView. collectionView need to horizontal scroll image, tableView for vertical scroll posts. When I had 3 rows I had no problems, but when i create 4 rows i have a problem with scrolling items inside rows. If I start scrolling on 4 row, scrolling is repeated on row 1 and the same thing if i start scrolling on 1 row scrolling is repeating on row 4.
What could be the problem and how to solve it? May be
Can check .gif file. I start on 1 row on name "Oko" and if i scrolling down on 4 row and scroll right collectionCell and return on 1 row i see next image name "City", but there must be name "Oko"
My code:
ViewController:
class PhotoStudiosViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchResultsUpdating {
#IBOutlet weak var tableView: UITableView!
var theStudios: [Studio] = []
var filteredStudios: [Studio] = []
var studiosRef: DatabaseReference!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
tableView.estimatedRowHeight = 475
tableView.rowHeight = UITableViewAutomaticDimension
}
override func viewDidLoad() {
super.viewDidLoad()
studiosRef = Database.database().reference(withPath: "PhotoStudios1")
studiosRef.observe(.value, with: { (snapshot) in
for imageSnap in snapshot.children {
let studioObj = Studio(snapshot: imageSnap as! DataSnapshot)
self.theStudios.append(studioObj)
}
self.tableView.reloadData()
})
}
// MARK: - TableView
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if searchController.isActive && searchController.searchBar.text != "" {
return filteredStudios.count
}
return theStudios.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! PhotoStudiosTableViewCell
cell.currentPageNumber.text = "1/\(theStudios[indexPath.row].halls.count)"
if searchController.isActive && searchController.searchBar.text != nil {
cell.theHalls = filteredStudios[indexPath.row].halls
} else {
cell.theHalls = theStudios[indexPath.row].halls
}
cell.nameLabel.text = theStudios[indexPath.row].studioName
cell.addressLabel.text = theStudios[indexPath.row].studioAddress
cell.logoLabel.sd_setImage(with: URL(string: theStudios[indexPath.row].studioLogo))
cell.didSelectAction = {
(innerPath) in
self.showDetailsView(indexPath, cellPath: innerPath)
}
return cell
}
TableViewCell:
class PhotoStudiosTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UIScrollViewDelegate, UICollectionViewDelegateFlowLayout {
#IBOutlet weak var button: UIButton!
#IBOutlet weak var logoLabel: UIImageView!
#IBOutlet weak var nameLabel: UILabel!
#IBOutlet weak var addressLabel: UILabel!
#IBOutlet weak var collectionView: UICollectionView!
#IBOutlet weak var currentPageNumber: UILabel!
var didSelectAction: ((IndexPath) -> ())?
var theHalls: [Hall] = [] {
didSet {
collectionView.reloadData()
}
}
var lastContentOffset = CGPoint.zero
override func prepareForReuse() {
super.prepareForReuse()
resetCollectionView()
}
override func awakeFromNib() {
super.awakeFromNib()
currentPageNumber.layer.zPosition = 2
currentPageNumber.layer.cornerRadius = 15.0
currentPageNumber.clipsToBounds = true
}
func resetCollectionView() {
guard !theHalls.isEmpty else { return }
theHalls = []
collectionView.reloadData()
}
// MARK: - CollectionView
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return theHalls.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as! PhotoStudiosCollectionViewCell2
cell.hallName.text = theHalls[indexPath.item].hallName
cell.priceLabel.text = theHalls[indexPath.item].hallPrice
cell.metrslabel.text = theHalls[indexPath.item].hallMetrs
cell.photoStudioImage.sd_setImage(with: URL(string: theHalls[indexPath.item].hallImage))
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
didSelectAction?(indexPath)
}
}
You're reusing the collection views in your cells, which is correct, but that means the contentOffset is also left from whatever was scrolled to previously when a cell is reused. It should be sufficient to just reset the contentOffset in cellForRowAtIndexPath when you are setting up your cell by doing something like:
cell.collectionView.contentOffset = .zero
One thing worth mentioning is that I do see you have a property called lastContentOffset in your cells that doesn't do anything yet and I suspect you are going to try to use that to persist the offset for a given cell when it scrolls out of view so that you can set it again when it comes back into view (rather than always resetting).
If you are going to do that, having the property in the cell won't work. You'll need to have a list of offsets for each cell stored alongside your data models in the containing view controller. Then you might save the offset for a given cell in didEndDisplayingCell and setting it in cellForRowAtIndexPath instead of .zero as I did above.

Can't call object from another class

I have a table view with expanding cells. The expanding cells come from a xib file. In the class of the table is where all of the code is that controls the expansion and pulling data from plist. I'm trying to add a close button but only want it to show when the cell is expanded. As it stands, I can't reference the button to hide it because it's in another class. Here is how I am trying to access it:
import UIKit
class SecondPolandViewController: UIViewController {
#IBOutlet weak var tableView: UITableView!
var customTableViewCell:CustomTableViewCell? = nil
var items = [[String:String]]()
override func viewDidLoad() {
super.viewDidLoad()
**REFERENCING CLASS**
customTableViewCell = CustomTableViewCell()
let nib = UINib.init(nibName: "CustomTableViewCell", bundle: nil)
self.tableView.register(nib, forCellReuseIdentifier: "cell")
self.items = loadPlist()
}
func loadPlist()->[[String:String]]{
let path = Bundle.main.path(forResource: "PolandResourceList", ofType: "plist")
return NSArray.init(contentsOf: URL.init(fileURLWithPath: path!)) as! [[String:String]]
}
var selectedIndex:IndexPath?
var isExpanded = false
func didExpandCell(){
self.isExpanded = !isExpanded
self.tableView.reloadRows(at: [selectedIndex!], with: .automatic)
}
}
extension SecondPolandViewController:UITableViewDataSource, UITableViewDelegate{
***HIDING BUTTON***
let button = customTableViewCell?.closeButton
button?.isHidden = true
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedIndex = indexPath
self.didExpandCell()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell
cell.selectionStyle = .none
let item = self.items[indexPath.row]
cell.titleLabel.text = item["title"]
cell.shortLabel.text = item["short"]
cell.otherImage.image = UIImage.init(named: item["image"]!)
cell.thumbImage.image = UIImage.init(named: item["image"]!)
cell.longLabel.text = item["long"]
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let height = UIScreen.main.bounds.height
if isExpanded && self.selectedIndex == indexPath{
//return self.view.frame.size.height * 0.6
return 400
}
return 110
//return height * 0.2
}
}
This does not hide it though.
Here is the xib that I am calling from if it helps. It is probably simple, I am just a newly self taught developer.
import UIKit
class CustomTableViewCell: UITableViewCell {
#IBOutlet weak var closeButton: UIImageView!
#IBOutlet weak var otherImage: UIImageView!
#IBOutlet weak var thumbImage: UIImageView!
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet weak var shortLabel: UILabel!
//#IBOutlet weak var longLabel: UITextView!
#IBOutlet weak var longLabel: UITextView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
//let width = UIScreen.main.bounds.width
//let height = UIScreen.main.bounds.height
//thumbImage.frame.size.width = height * 0.19
//thumbImage.frame.size.height = height * 0.19
}
}
It seems like that you just need to add these lines into cellForRowAt:indexPath method:
if indexPath == selectedIndexPath {
cell.closeButton.isHidden = false
} else {
cell.closeButton.isHidden = true
}
You may add them right before return line
The normal iOS answer for this is a delegate, but you could get away with a simple closure in this case.
In CustomTableViewCell, add
public var closeTapped: ((CustomTableViewCell) -> ())?
Then in that class, when close is tapped, call
self.closeTapped?(self)
In the VC, in cellForRowAt,
cell.closeTapped = { cell in
// do what you want with the VC
}
For delegates, this might help: https://medium.com/#jamesrochabrun/implementing-delegates-in-swift-step-by-step-d3211cbac3ef
The quick answer to why to prefer delegates over the closure is that its a handy way to group a bunch of these together. It's what UITableViewDelegate is (which you are using). Also, it's a common iOS idiom.
I wrote about this here: https://app-o-mat.com/post/how-to-pass-data-back-to-presenter for a similar situation (VC to VC communication)

How to add multiple collection view in a view

I am trying to incorporate 2 collection views into same view. I implemented everything and noticed that the data that is loading in the second collection view is the same as the first collection view.
Here is the code that i am trying out
class DashBoardMainSection1CollectionViewCellClass: UICollectionViewCell
{
#IBOutlet weak var DashBoardMainSection1CollectionViewImageListingViewOutlet : UIImageView!
#IBOutlet weak var DashBoardMainSection1CollectionViewLabelOutlet : UILabel!
}
class DashBoardMainSection2CollectionViewCellClass: UICollectionViewCell
{
#IBOutlet weak var DashBoardMainSection2CollectionViewImageListingViewOutlet : UIImageView!
#IBOutlet weak var DashBoardMainSection2CollectionViewLabelOutlet : UILabel!
}
private let reuseIdentifierDashBoardMainSection1Cell = "dashBoardMainSection1CollectionViewCellIdentifier"
private let reuseIdentifierDashBoardMainSection2Cell = "dashBoardMainSection2CollectionViewCellIdentifier"
class DashBoardViewControllerMain: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout
{
#IBOutlet weak var DashBoardMainSection1CollectionViewOutlet : UICollectionView!
#IBOutlet weak var DashBoardMainSection2CollectionViewOutlet : UICollectionView!
override func viewDidLoad()
{
super.viewDidLoad()
DashBoardMainSection1CollectionViewOutlet.delegate = self;
DashBoardMainSection2CollectionViewOutlet.delegate = self;
DashBoardMainSection1CollectionViewOutlet.dataSource = self;
DashBoardMainSection2CollectionViewOutlet.dataSource = self;
// Do any additional setup after loading the view.
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
var count:Int?
if (self.DashBoardMainSection1CollectionViewOutlet) != nil{
count = 10
}
//if (self.DashBoardMainSection2CollectionViewOutlet) != nil{
else{
count = 5
}
return count!
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let collectionView = self.DashBoardMainSection1CollectionViewOutlet{
let cell:DashBoardMainSection1CollectionViewCellClass = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierDashBoardMainSection1Cell, for: indexPath) as! DashBoardMainSection1CollectionViewCellClass
cell.DashBoardMainSection1CollectionViewImageListingViewOutlet.image = UIImage(named:"Apple.png")
cell.DashBoardMainSection1CollectionViewLabelOutlet.text = "FIRST"
return cell
}
else{
let cell2:DashBoardMainSection2CollectionViewCellClass = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierDashBoardMainSection2Cell, for: indexPath) as! DashBoardMainSection2CollectionViewCellClass
cell2.DashBoardMainSection2CollectionViewImageListingViewOutlet.image = UIImage(named:"Logo-Disabled.png")
cell2.DashBoardMainSection2CollectionViewLabelOutlet.text = "SECOND"
return cell2
}
}
When i run the project both the collection views are showing Apple picture and the cell count is 10.
Can someone help me to solve this issue...
Please manage both collectionview with tag. Give tag to both collectionview on viewDidLoad method or from storyboard. Now make conditions based on tag.
Example :-
DashBoardMainSection1CollectionViewOutlet.tag = 1
DashBoardMainSection2CollectionViewOutlet.tag = 2
if collectionView.tag == 1 {
return 10
} else {
return 5
}
The problem is in the if statement:
It should be like this:
if collectionView == self.DashBoardMainSection1CollectionViewOutlet{
//code
}
With this code, you check if the collectionView passed by the parameter is the first collectionView.
With your original code, you were making new constant named collectionView and assigning it with your first collectionView.
Because your condition if (self.DashBoardMainSection1CollectionViewOutlet) != nil, will always return true and code for if block will only execute everytime.
Try this:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
var count = 0
if (collectionView == self.DashBoardMainSection1CollectionViewOutlet) {
count = 10
}
// if (collectionView == self.DashBoardMainSection2CollectionViewOutlet)
else {
count = 5
}
return count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (collectionView == self.DashBoardMainSection1CollectionViewOutlet){
let cell:DashBoardMainSection1CollectionViewCellClass = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierDashBoardMainSection1Cell, for: indexPath) as! DashBoardMainSection1CollectionViewCellClass
cell.DashBoardMainSection1CollectionViewImageListingViewOutlet.image = UIImage(named:"Apple.png")
cell.DashBoardMainSection1CollectionViewLabelOutlet.text = "FIRST"
return cell
}
else{
let cell2:DashBoardMainSection2CollectionViewCellClass = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierDashBoardMainSection2Cell, for: indexPath) as! DashBoardMainSection2CollectionViewCellClass
cell2.DashBoardMainSection2CollectionViewImageListingViewOutlet.image = UIImage(named:"Logo-Disabled.png")
cell2.DashBoardMainSection2CollectionViewLabelOutlet.text = "SECOND"
return cell2
}
}
If you get same data for both UICollectionView it means you are using the same DataSource.
Define a separate DataSource for each UICollectionView
And you should do the same for the Delegate except if you need to implement same actions for both.

dynamic tableview inside custom tableviewcell

I'm trying to create a tableview with custom cells that each one holds a tableview.
I want to show the inner tableview just when it have some data (most of the time it's empty). I've managed to display the cells but can't display their tableview if it's populated with data.
The problem also is that the cell height needs to be dynamic according to the amount of data to display.
The cell code:
class feedViewCell: UITableViewCell , UITableViewDataSource , UITableViewDelegate {
#IBOutlet var feedCellImage: UIImageView!
#IBOutlet var feedCellUserName: UILabel!
#IBOutlet var feedCellDate: UILabel!
#IBOutlet var feedCellComments: UILabel!
#IBOutlet var cardView: UIView!
#IBOutlet var repliesTableView: UITableView!
var repliesArray:[Reply] = []
#IBAction func addComment(sender: AnyObject) {
}
override func awakeFromNib() {
super.awakeFromNib()
var nib = UINib(nibName: "feedComment", bundle: nil)
repliesTableView.registerNib(nib, forCellReuseIdentifier: "commentCell")
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
override func layoutSubviews() {
cardSetup()
}
func cardSetup() {
cardView.layer.masksToBounds = false
cardView.layer.cornerRadius = 5
cardView.layer.shadowOffset = CGSizeMake(-0.2, 0.2)
cardView.layer.shadowRadius = 1
cardView.layer.shadowOpacity = 0.2
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return repliesArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = repliesTableView.dequeueReusableCellWithIdentifier("commentCell", forIndexPath: indexPath) as CommentFeedCell
cell.commentCellUserName.text = repliesArray[indexPath.row].userName
return cell
}
}
And the Main controller code:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var comment = comments[indexPath.row]
let cell: feedViewCell = tableView.dequeueReusableCellWithIdentifier("feedCell", forIndexPath: indexPath) as feedViewCell
cell.feedCellUserName.text = comment.userName
cell.feedCellImage.backgroundColor = UIColor.redColor()
cell.feedCellComments.text = "\(comment.replies.count) COMMENTS"
cell.repliesArray = comment.replies
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyy"
cell.feedCellDate.text = dateFormatter.stringFromDate(NSDate())
if cell.repliesArray.count > 0 {
cell.repliesTableView.rowHeight = UITableViewAutomaticDimension
}
cell.repliesTableView.reloadData()
return cell
}
How to show the inner tableview only in cells which have comments (and hiding the tableview in cells with 0 comments)?
Call super in layoutSubviews and let us know what happens.
override func layoutSubviews() {
super.layoutSubviews()
cardSetup()
}

Resources