Reload collection view data from another view class - ios

I have two containers in a view. The top one has a collection view.
I want to update my collection view from a button when a button is hit from the below container. My button is also changing the value of an array, which my collection view uses.
I thought didSet would do the job but unfortunately did not work.
Top:
class TopViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
#IBOutlet weak var favoritesCV: UICollectionView!
var myFavorites = [] {
didSet {
self.favoritesCV.reloadData()
}
}
override func viewDidAppear(animated: Bool) {
myFavorites = favoritesInstance.favoritesArray
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return myFavorites.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell : FavoritesCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! FavoritesCollectionViewCell
var myPath = myFavorites[indexPath.row] as! String
cell.myImage.image = UIImage(named: myPath)
return cell
}
}
Bottom:
class BottomViewController: UIViewController, UIScrollViewDelegate {
#IBAction func addFavorites(sender: AnyObject) {
favoritesInstance.favoritesArray.append("aaaa.jpg")
}
}
Storage Class:
class Favorites {
var favoritesArray:Array <AnyObject>
init(favoritesArray:Array <AnyObject>) {
self.favoritesArray = favoritesArray
}
}
var favoritesInstance = Favorites(favoritesArray:[])

I have added
NSNotificationCenter.defaultCenter().addObserver(self, selector: "loadList:", name:"load", object: nil)
in my viewdidload of my collection view class.
also added a selector which reloads my data when it is called by the Notification Center
func loadList(notification: NSNotification){
self.favoritesCV.reloadData()
}
and for the other class where the button is pressed:
NSNotificationCenter.defaultCenter().postNotificationName("load", object: nil)
Swift 3:
NotificationCenter.default.addObserver(self, selector: #selector(loadList), name:NSNotification.Name(rawValue: "load"), object: nil)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)

Swift 4:
1st class:
NotificationCenter.default.post(name: NSNotification.Name("load"), object: nil)
Class with collectionView:
in viewDidLoad():
NotificationCenter.default.addObserver(self, selector: #selector(loadList(notification:)), name: NSNotification.Name(rawValue: "load"), object: nil)
and function:
#objc func loadList(notification: NSNotification) {
self.collectionView.reloadData()
}

Great! I was looking for this. In Swift 3 the code is slightly different. In collectionviewcontroller:
NotificationCenter.default.addObserver(self, selector: #selector(RoundCollectionViewController.load), name:NSNotification.Name(rawValue: "reload"), object: nil)
and in the other one:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)

Related

How to bring out the viewController after menu item is selected?

Im trying to bring out the viewcontroller after i select an item in the menu. Currently, when I press something it just change the page, but it gets stuck on the right side. How do i bring that out.
This is the code that i wrote.
class ContainerVC: UIViewController {
var sideMenuOpen = false
#IBOutlet weak var mainView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(toggleSideMenu),
name: NSNotification.Name("ToggleSideMenu"),
object: nil)
}
#IBOutlet weak var sideMenuConstraint: NSLayoutConstraint!
#objc func toggleSideMenu() {
if sideMenuOpen {
sideMenuOpen = false
sideMenuConstraint.constant = -270
} else {
sideMenuOpen = true
sideMenuConstraint.constant = 0
}
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
}
And this is what i wrote in my SideMenuVC
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
// NotificationCenter.default.post(name: NSNotification.Name ("ToggleSideMenu"), object: nil)
switch indexPath.row {
case 0: NotificationCenter.default.post(name: NSNotification.Name ("ShowProfile"), object: nil)
case 8: //signs out of Firebase
try? Auth.auth().signOut()
//signs out of Facebook
FBSDKAccessToken.setCurrent(nil)
let main = UIStoryboard(name: "Main", bundle: nil)
let second = main.instantiateViewController(withIdentifier: "loginPage")
self.present(second, animated: true, completion: nil)
default: break
//https://www.youtube.com/watch?v=Hl_Re_KLhcY
}
}
And this is what i wrote in my HomeVC
#IBAction func menuButton() {
print("Toggle Side Menu")
NotificationCenter.default.post(name: NSNotification.Name("ToggleSideMenu"), object: nil)
}
i would like the selected page to come out.
Just add NotificationCenter.default.post(name: NSNotification.Name ("ToggleSideMenu"), object: nil) to your didSelectRowAt

Scroll UITableView to certain indexPath depending on selection

I have a UITableView with a custom cell. The custom cell as three buttons covering the entire span of the cell. I am trying to scroll the tableview automatically depending on which label the user selects.
I tried using NotificationCenter but it crashes when trying to scroll. Is there a more elegant solution?
Edit: My end goal is to have the user click on optionOne and have it scroll to the cell immediately below. The trick is doing this without cellForRowAt because I'm handling it in the cell due to the multiple buttons.
Custom Cell:
#IBOutlet weak var optionOneLabel: UILabel!
#IBOutlet weak var optionTwoLabel: UILabel!
#IBOutlet weak var optionThreeLabel: UILabel!
override func prepareForReuse() {
super.prepareForReuse()
let optionOne = UITapGestureRecognizer(target: self, action: #selector(CustomCell.optionOnePressed(_:)))
optionOneLabel.addGestureRecognizer(optionOne)
let optionTwo = UITapGestureRecognizer(target: self, action: #selector(CustomCell.optionTwoPressed(_:)))
optionTwoLabel.addGestureRecognizer(optionTwo)
let optionThree = UITapGestureRecognizer(target: self, action: #selector(CustomCell.optionThreePressed(_:)))
optionThreeLabel.addGestureRecognizer(optionThree)
}
#objc func optionOnePressed(_ sender: UITapGestureRecognizer) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scrollTableOptionOne"), object: nil)
}
#objc func optionTwoPressed(_ sender: UITapGestureRecognizer) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scrollTableOptionTwo"), object: nil)
}
#objc func optionThreePressed(_ sender: UITapGestureRecognizer) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scrollTableOptionthree"), object: nil)
}
TableViewController
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(optionOne), name: NSNotification.Name(rawValue: "scrollTableOptionOne"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(optionTwo), name: NSNotification.Name(rawValue: "scrollTableOptionTwo"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(optionThree), name: NSNotification.Name(rawValue: "scrollTableOptionThree"), object: nil)
}
#objc func optionOne() {
let indexPath = NSIndexPath(item: posts.count, section: 0)
tableView.scrollToRow(at: indexPath as IndexPath, at: UITableViewScrollPosition.init(rawValue: indexPath.row + 2)!, animated: true)
}
#objc func optionTwo() {
print("Don't scroll this one for now")
}
#objc func optionThree() {
print("Don't scroll this one for now")
}
Let me know if you need more information. Thanks.
Rather than use notifications, you could set up a callback on the cell with the buttons so that when one of them is tapped, the callback is run with the information about which button was tapped so that the view controller can do what it needs to with it:
As an example of what you want to do I've created a sample project which you can download and look at (Xcode 9.4.1, Swift 4.1) It's a bit messy, but it does what you need: https://bitbucket.org/abizern/so51758928/src/master/
The specifics are, firstly, set up the cell with the buttons to handle the callback:
class SelectionCell: UITableViewCell {
enum Button {
case first
case second
case third
}
var callback: ((Button) -> Void)?
#IBAction func firstButtonSelected(_ sender: UIButton) {
callback?(.first)
}
#IBAction func secondButtonSelected(_ sender: UIButton) {
callback?(.second)
}
#IBAction func thirdButtonSelected(_ sender: UIButton) {
callback?(.third)
}
}
Using an enum for the buttons makes the code cleaner than just raw numbers to identify a button. Each button calls the callback identifying itself.
In the table view controller, when you set up the cells in the delegate, you pass this callback to the cell:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let value = values[indexPath.row]
switch value {
case .header:
let cell = tableView.dequeueReusableCell(withIdentifier: "Selection", for: indexPath) as! SelectionCell
cell.callback = handler
return cell
case .value:
let cell = tableView.dequeueReusableCell(withIdentifier: "Display", for: indexPath) as! DisplayCell
cell.configure(with: value)
return cell
}
}
Note, I've passed handler not handler() so that it passed the closure, not the result of running the closure, to the cell. It's the cell that runs the closure.
The callback looks like this (for my example, your needs will be different)
I'm using the button identifier that is passed in to the closure to identify the IndexPath that I'm interested in and scrolling it to the top
private func handler(button: SelectionCell.Button) -> Void {
print("selected \(button)")
let index: Int?
switch button {
case .first:
index = values.index(where: { (value) -> Bool in
if case .value("First") = value {
return true
}
return false
})
case .second:
index = values.index(where: { (value) -> Bool in
if case .value("Second") = value {
return true
}
return false
})
case .third:
index = values.index(where: { (value) -> Bool in
if case .value("Third") = value {
return true
}
return false
})
}
guard let row = index else { return }
let indexPath = IndexPath(row: row, section: 0)
tableView.scrollToRow(at: indexPath, at: .top, animated: true)
}
As I've already said, you can look at the example project to see how this all works, but these are the important steps.
Use the cell that sends the notification as the sender object instead of nil. In your cell do:
NotificationCenter.default.post(
name: NSNotification.Name(rawValue: "scrollTableOptionOne"),
object: self)
Change your notification handler so that it can access to the notification. Retrieve the cell from the notification and find out the indexPath.
#objc func optionOne(ntf: Notification) {
let cell = ntf.object as! UITableViewCell
if let indexPath = tableView.indexPath(for: cell) {
tableView.scrollToRow(at: indexPath,
at: .bottom, animated: true)
}
}
I think this is the reason for crashing.
For performance reasons, you should only reset attributes of the cell
that are not related to content, for example, alpha, editing, and
selection state. The table view's delegate in
tableView(_:cellForRowAt:) should always reset all content when
reusing a cell
Refer this
You can make use of Closures or Delegate instead of going with notification
I think you need to change code like this
let indexPath = IndexPath(row: posts.count - 1, section: 0)
tableView.scrollToRow(at: indexPath, at: .top, animated: true)
This will scroll your row to top in table view.
ScrollToRow method having some problem. UITableViewScrollPosition holds the values - none, top, middle, bottom enum values.
Change the line:
tableView.scrollToRow(at: indexPath as IndexPath, at: UITableViewScrollPosition.init(rawValue: indexPath.row + 2)!, animated: true)
To:
tableView.scrollToRow(at: indexPath as IndexPath, at: .top, animated: true)
In order to track indexpath, set row value to cell's tag, in cellForRow:
cell.tag = indexPath.row
And post notification as:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scrollTableOptionOne"), object: self.tag)
#objc func optionOne(_ notification: Notification) {
let indexPath = NSIndexPath(item: notification.object+1, section: 0)
tableView.scrollToRow(at: indexPath as IndexPath, at: UITableViewScrollPosition.init(rawValue: indexPath.row + 2)!, animated: true)
}
Better approach will be using closures:
#IBOutlet weak var optionOneLabel: UILabel!
#IBOutlet weak var optionTwoLabel: UILabel!
#IBOutlet weak var optionThreeLabel: UILabel!
var callBackOnLabel : (()->())? /// Add this in cell.
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let optionOne = UITapGestureRecognizer(target: self, action: #selector(CustomCell.optionOnePressed(_:)))
optionOneLabel.addGestureRecognizer(optionOne)
}
#objc func optionOnePressed(_ sender: UITapGestureRecognizer) {
self.callBackOnLabel?()
}
Then in your cellForRowAt:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell.callBackOnLabel = {
let selectedIndex = IndexPath(row: posts.count, section: 0)
tableView.scrollToRow(at: selectedIndex, at: .middle, animated: true)
}
}
In the same way you can add for other two labels or you can make it generic to accept the response in single call back and perform the animation.

how to pass string data from swift to objective c class using notification

I want to pass table cell text label data from swift class to objective c class. In swift class I did the following,
class NewsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var newsTableView: UITableView!
var myVC:NewsDetailsViewController!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
print("selected index :",indexPath.row)
let selectedCell = tableView.cellForRow(at: indexPath)
print("did select and the text is \(selectedCell?.textLabel?.text)")
myVC.passedValue = selectedCell?.textLabel?.text
print("text label value: ", myVC.passedValue)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "PostQuestion"), object: myVC.passedValue)
self.present(myVC, animated: true , completion: nil)
}
Now I want to receive this string data with my another controller which is a objective c class. Kindly guide.
You should send your notification with
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "PostQuestion"),
object: self,
userInfo: ["value": myValue] as Dictionary<AnyHashable, Any>)
and process the notifications it with something like
func processNotification(notification: NSNotification) {
let userInfo = notifcation.userInfo
if let value = userInfo?["value"] as? String {
...
}
}
or the same in Objective-C
- (void)processNotification:(NSNotification *)notification {
NSString *value = [notifcation.userInfo objectForKey:#"value"]
if(value) {
...
}
}

UICollectionViewCell Animation With Protocol

Im trying to animate my menu which made with UICollectionView. I have 2 more collection view which you can see in the below.
And I'm trying to animate top bar when scrolled down. When animation is completed the "Pokemon" label will be white, the pokemon image will be hidden, and the background will be blue. I use protocol to reach cell. This is my ViewController class.
protocol TopCategoriesDelegator{
func openTopBar()
func closeTopBar()}
And this is cellForRowAt function
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.collectionView{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "topCategory", for: indexPath) as! TopCategoriesCell
cell.viewController = self
return cell
}else if collectionView == subCategoriesCollectionView{
return collectionView.dequeueReusableCell(withReuseIdentifier: "subCategories", for: indexPath)
}else{
return collectionView.dequeueReusableCell(withReuseIdentifier: "productCell", for: indexPath)
}
}
And for detection of scrolling down;
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// print(scrollView.contentOffset.y)
if scrollView.contentOffset.y > 160 {
if self.cellDelegate != nil{
self.cellDelegate.closeTopBar() // func in main vc for background color and size
closeAnimation()
}
}else{
if self.cellDelegate != nil{
self.cellDelegate.openTopBar() // func in main vc for background color and size
openAnimation()
}
}
}
And this is the TopCategoriesCell class
override func layoutSubviews() {
if let vc = viewController as? ProductsVC{
vc.cellDelegate = self
}
}
func closeTopBar() {
UIView.animate(withDuration: 0.3) {
self.categoryImage.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
self.categoryImage.isHidden = true
}
}
func openTopBar(){
UIView.transition(with: categoryImage, duration: 0.3, options: .curveEaseIn, animations: {
self.categoryImage.isHidden = false
self.categoryName.textColor = UIColor().rgb(red: 37.0, green: 110.0, blue: 140.0)
}, completion: nil)
}
Actually everything works fine. But only first element dissappear the others stays there like this;
How can i hide other cell's images ?
Thank You.
You have set the cell delegate of the view controller to be the cell. This seems unnecessary.
It also means that as there is only one view controller, and delegates are a one-to-one communication pattern, your view controller only hides the image on one cell.
To fix this use NotificationCenter in the TopCategoriesCell initialiser as follows:
init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
NotificationCenter.default.addObserver(self, selector: #selector(TopCategoriesCell.closeTopBar), name: NSNotification.Name(rawValue: "scrolledDown"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(TopCategoriesCell.openTopBar), name: NSNotification.Name(rawValue: "scrolledUp"), object: nil)
}
Note that which init function you place it in depends on how you are instantiating the cell.
Then, in your view controller:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y > 160 {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scrolledDown"), object: nil)
} else {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scrolledUp"), object: nil)
openAnimation()
}
}
And in the TopCategoriesCell:
deinit {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "scrolledDown"), object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "scrolledUp"), object: nil)
}

Displaying TableView and CustomCell troubles on iPhone4s

I have some trouble with the appearance of my tableviews and cells on the iphone4s. Within the simulator and on new devices everything is fine.
UITableViewController
The custom table cell (picture 1) isn't presented correctly. All the labels etc. lie on top of each other. They should be shown one below the other like they do on the simulator.
ViewController with TableView
The other custom cells even don't show on the iPhone4s only a gray square appears.
I'm using Auto Layout. Do you have any suggestions?
Here's the code:
1st picture:
import UIKit
class FeedController: TableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// adjusting text size without quitting app
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "onContentSizeChange:",
name: UIContentSizeCategoryDidChangeNotification,
object: nil)
// set table row height
tableView.estimatedRowHeight = 89
tableView.rowHeight = UITableViewAutomaticDimension
// removes the back button after clicked on send button to write a post
self.navigationItem.hidesBackButton = true
// refresh control
self.refreshControl = UIRefreshControl()
self.refreshControl!.addTarget(self, action: Selector("refresh:"), forControlEvents: UIControlEvents.ValueChanged)
self.refreshControl!.backgroundColor = UIColor.grayColor()
self.refreshControl!.tintColor = UIColor.whiteColor()
self.tableView.addSubview(refreshControl!)
}
func reloadFeed(note: NSNotification){
tableView.reloadData()
}
func refresh(sender: AnyObject){
self.refreshControl!.endRefreshing()
}
// called when the text size was changed by the user
func onContentSizeChange(notification: NSNotification) {
tableView.reloadData()
}
}
import Foundation
import UIKit
class TableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource, PDeliversStatusAlerts {
let notifCenter = NSNotificationCenter.defaultCenter()
override init() {
super.init()
notifCenter.addObserver(self, selector: "displayConnectionLostAlert", name: kConnectionLostNotification, object: self)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
notifCenter.addObserver(self, selector: "displayConnectionLostAlert", name: kConnectionLostNotification, object: self)
}
func displaySimpleAlert(#title:String, message:String){
var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
func displayModalDialog(#title: String, message: String, yesHandler: ((UIAlertAction!) -> Void)?, noHandler: ((UIAlertAction!) -> Void)?) {
var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: yesHandler))
alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: noHandler))
self.presentViewController(alert, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func push(sender: AnyObject) {
}
//Tableview
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
2nd picture:
import UIKit
class NextViewController: ViewController, UITableViewDelegate, UITableViewDataSource{
var followedFeed : FollowedHashtagFeed?
var hottestFeed : HottestHashtagFeed?
var nearbyFeed : NearbyHashtagFeed?
var hashtagFeed : HashtagFeed?
#IBAction func hottestButtonTapped(sender:AnyObject) {
hashtagFeed = FeedFactory.instance().hottestHashtagFeed()
notifCenter.removeObserver(self)
notifCenter.addObserver(self, selector: "reloadFeed", name: hashtagFeed?.notificationName, object: nil)
hashtagFeed!.subscribe()
reloadFeed()
}
#IBAction func nearbyButtonTapped(sender: AnyObject) {
hashtagFeed = FeedFactory.instance().nearbyHashtagFeed()
notifCenter.removeObserver(self)
notifCenter.addObserver(self, selector: "reloadFeed", name: hashtagFeed?.notificationName, object: nil)
notifCenter.addObserver(self, selector: "didReceiveLocationPermissionNeededNotification:", name: "location_permission_needed", object: nil)
hashtagFeed!.subscribe()
reloadFeed()
}
#IBAction func followedButtonTapped(sender: AnyObject) {
hashtagFeed = FeedFactory.instance().followedHashtagFeed()
notifCenter.removeObserver(self)
notifCenter.addObserver(self, selector: "reloadFeed", name: hashtagFeed?.notificationName, object: nil)
hashtagFeed!.subscribe()
reloadFeed()
}
override func viewDidLoad() {
super.viewDidLoad()
//set table row height
tableView.rowHeight = UITableViewAutomaticDimension
//load feed cell
var nipName=UINib(nibName: "NextTableCell", bundle:nil)
self.tableView.registerNib(nipName, forCellReuseIdentifier: "nextCell")
followedButtonTapped(followedButton)
view.setNeedsLayout()
view.layoutIfNeeded()
println("Frame Height:")
println(tableView.frame.height)
println(tableView.bounds.height)
println("Frame Width:")
println(self.tableView.frame.width)
println(self.tableView.bounds.width)
/*
hashtagFeed = FeedFactory.instance().followedHashtagFeed()
//subscribe to feed changes
notifCenter.addObserver(self, selector: "reloadFeed", name: hashtagFeed?.notificationName, object: nil)
hashtagFeed!.subscribe()*/
}
func didReceiveLocationPermissionNeededNotification(note: NSNotification){
displayModalDialog(
title: "Location Permission Needed",
message: "In order to use this functionality the app needs your permission to use location data - do you want to give this permission now?",
yesHandler: {
(action: UIAlertAction!) in LocationHelper.instance().askForPermission()
},
noHandler: nil
)
}
//Tableview
func reloadFeed(){
tableView.reloadData()
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return hashtagFeed!.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("nextCell", forIndexPath: indexPath) as NextTableCell
let hashtag = hashtagFeed!.toArray()[indexPath.row]
cell.loadItem(hashtag)
return cell
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
}
}
This sort of issue can present itself when the constraints set up for the cell's subviews do not enforce a specific height for the cell.
For example, if you have a cell that contains a single subview, and the subview has top/bottom/left/right constraints to its superview (nearest neighbor, i.e. the cell's contentView) of 10px, but the subview itself does not have a height constraint, the cell will not be laid out properly.
This can look like all cells on top of one another, or all cells presented with the default 44px height.
To fix the issue (if we're working with the example view hierarchy of a cell with a single subview), define a height constraint for the subview. You might also need to set the height constraint's priority to something less than 1000.
Not sure if this will fix your specific issue, but it's fixed similar issues for me, so presenting it here as an option.
For what it's worth, I'm fairly certain that your issue is constraints-related, which means the code above wont really help answer the question.

Resources