tableviewcell changing the images while scrolling - swift

I have four button inside a tableview cell and each of the button has a unique as 0,1,2 and 3 respectively.
These four buttons and linked to a single button action method.
The code inside tableviewcell is as follows:
#IBOutlet weak var questionLbl: UILabel!
#IBOutlet weak var q1: UIButton!
#IBOutlet weak var q2: UIButton!
#IBOutlet weak var q3: UIButton!
#IBOutlet weak var q4: UIButton!
typealias emptyButtonClosure = (String,Int) -> ()
var buttonTapped:emptyButtonClosure?
#IBAction func btnClicked(sender:UIButton){
let buttonArray = [q1,q2,q3,q4]
for button in buttonArray {
if sender.tag == button!.tag{
button!.isSelected = true;
if let buttonTapped = buttonTapped{
buttonTapped(sender.titleLabel!.text!,sender.tag)
}
if let image = UIImage(named: "checked-radio") {
button!.setImage(image, for: .normal)
}
else
{
let image1 = UIImage(named: "unchecked-radio")
button!.setImage(image1, for: .normal)
}
}else{
button!.isSelected = false;
if let image = UIImage(named: "unchecked-radio") {
button!.setImage(image, for: .normal)
}
else
{
let image1 = UIImage(named: "checked-radio")
button!.setImage(image1, for: .normal)
}
}
}
}
These buttons are grouped into single array called as buttonarray because these buttons are radio buttons and only single selection is allowed.
Now the issue is,the value is fetched correctly for each cell in the tableview.But when the tableview is scrolled,the image position keeps changing.The code inside tableview is as follows:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "questioncell", for: indexPath) as! ChildQuestionCell
cell.questionLbl.text = self.listData?.nanniBookingDetails.questionsData[indexPath.row].question
cell.q1.setTitle(self.listData?.nanniBookingDetails.questionsData[indexPath.row].option1, for: .normal)
cell.q2.setTitle(self.listData?.nanniBookingDetails.questionsData[indexPath.row].option2, for: .normal)
cell.q3.setTitle(self.listData?.nanniBookingDetails.questionsData[indexPath.row].option3, for: .normal)
cell.q4.setTitle(self.listData?.nanniBookingDetails.questionsData[indexPath.row].option4, for: .normal)
cell.buttonTapped = { value,index in
print("button selected is",value,index)
self.answers.append(value)
}
return cell
}
How to retain the image position even when it is scrolled.Like the image selected for 1st row should not be shown in 3rd or 4th row.It should remain only in 1st row.
Please let me know how to solve this?

Related

How to save array data locally

Here is my code. I want to learn how to save my dataSource for the like button of each cell. So that when the user leaves the app and returns later, the same cells that were liked remain liked.
This is new code from my last post. Since I don't want to keep making new arrays, I can try and locally save my dataSource variable which stores each cells Status of being liked or not.
ViewController -
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet var tableView: UITableView!
var dataSource: [TableModel] = []
var updatedCell = TableViewCell()
var updatedIndex = Int()
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .light
self.dataSource = Array(repeating: TableModel(isLiked: false), count: 8)
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.showsVerticalScrollIndicator = false
self.tableView.reloadData()
}
#IBAction func buttonSelected(_ sender: Any) {
// Update Cell for which UIButton (Like Button) was tapped.
dataSource[(sender as AnyObject).tag].isLiked = !dataSource[(sender as AnyObject).tag].isLiked
let indexPath = IndexPath(row: (sender as AnyObject).tag, section: 0)
tableView.reloadRows(at: [indexPath], with: .automatic)
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
// Saved updatedCell & updatedIndex variables for delegate pattern. To Update this VC's cells data when edited on secondVC (moreInfoViewController) in a way, made them accessible outside this function
// To Get Specific TableView Cell the user is interacting with.
updatedCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
updatedIndex = indexPath.row
// Go to Second VC and Send cell tapped data to next view
let vc = (storyboard?.instantiateViewController(identifier: "secondVC") as? moreInfoViewController)!
vc.delegate = self
// Get Status of Liked Button in the cell the user tapped and display if the user liked it previously in the SecondVC
let isLiked = dataSource[indexPath.row].isLiked
if isLiked {
// print("Liked")
vc.isLiked = true
} else {
// print("Not Liked")
vc.isLiked = false
}
present(vc, animated: true)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 8
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
// cell.moreBtn.isUserInteractionEnabled = false
cell.likeBtn.tag = indexPath.row
// cell.likeBtn.addTarget(self, action: #selector(buttonSelected(_:)), for: .touchUpInside)
// Get Each Cell Liked Button Status and display if the user liked or not Liked each cell
let isLiked = dataSource[indexPath.row].isLiked
if isLiked {
// User liked the post
cell.likeBtn.setImage(UIImage(named: "liked"), for: UIControl.State.normal)
} else {
// User Unliked the post
cell.likeBtn.setImage(UIImage(named: "unLiked"), for: UIControl.State.normal)
}
return cell
}
}
// Conform VC to protocol (VC2Delegate) located in "Structs.swift" File
extension ViewController: VC2Delegate {
func likeStatusDidChange(_ vc2: moreInfoViewController, to title: Bool) {
// set the text of the table cell here...
dataSource[updatedIndex].isLiked = !dataSource[updatedIndex].isLiked
let indexPath = IndexPath(row: updatedIndex, section: 0)
tableView.reloadRows(at: [indexPath], with: .automatic)
}
}
moreInfoViewController -
import UIKit
class moreInfoViewController: UIViewController {
#IBOutlet var backBtn: UIButton!
#IBOutlet var titleLabel: UILabel!
#IBOutlet var locationLabel: UILabel!
#IBOutlet var theImage: UIImageView!
#IBOutlet var mainlikeBtn: UIButton!
#IBOutlet var mainTypeLbl: UILabel!
var currentID:String = ""
var isLiked = Bool()
weak var delegate: VC2Delegate?
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .light
self.navigationController?.setNavigationBarHidden(true, animated: true)
styles()
// "isLiked" variable to display whether or user liked this event
if (isLiked == true) {
// is Liked
mainlikeBtn.setImage(UIImage(named: "liked"), for: UIControl.State.normal)
} else {
// Not Liked
mainlikeBtn.setImage(UIImage(named: "unLiked"), for: UIControl.State.normal)
}
}
// Heart/Like Button Action. User can like event in this VC with this button and it will tell the firstVC (ViewController) to update "Like Status" there also
#IBAction func likeBtnAction(_ sender: Any) {
if (isLiked == true) {
// is Liked
isLiked = false
mainlikeBtn.setImage(UIImage(named: "unLiked"), for: UIControl.State.normal)
} else {
isLiked = true
mainlikeBtn.setImage(UIImage(named: "liked"), for: UIControl.State.normal)
}
// When User interacts with like Button, this function gets called that tells the firstVC (ViewController) to update as well.
// likeStatusDidChange function is located at the bottom of the (ViewController) with extension ViewController.
delegate?.likeStatusDidChange(self, to: true)
}
// Go Back To FirstVC (ViewController)
#IBAction func previousVC(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
func styles() {
titleLabel.numberOfLines = 1
titleLabel.adjustsFontSizeToFitWidth = true
locationLabel.numberOfLines = 1
locationLabel.adjustsFontSizeToFitWidth = true
backBtn.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)
theImage.layer.borderColor = UIColor.black.cgColor
theImage.layer.borderWidth = 2
theImage.layer.cornerRadius = 10
}
}
When you get array from userdefaults it gives you Any type array so you need to cast it to Int array and check it nil or not before you use. So you can use this code block.
if let savedDataKey = UserDefaults.standard.array(forKey: "savedDataKey") as? [Int] {
print(savedDataKey)
}

Change UIButton Color in CollectionViewCell [duplicate]

This question already has answers here:
Change the color of UIButton in IBOutletCollection
(2 answers)
Closed 4 years ago.
I have two classes: ViewController and PercentCollectionViewCell.
When I tap on a button1_Tap the color is changed to blue. When I tap on a button2_Tap, the color of the second button turns blue, but the color of the first button does not turn back to white color.
PercentCollectionViewCell class:
class PercentCollectionViewCell: UICollectionViewCell {
#IBOutlet weak var firstPercent: UIButton!
#IBOutlet weak var secondPercent: UIButton!
}
ViewController class:
let cellIdentifiers:[String] = ["FirstPercentCell", "SecondPercentCell"]
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return cellIdentifiers.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let collectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifiers[indexPath.item], for: indexPath) as? PercentCollectionViewCell
collectionCell?.firstPercent?.addTarget(self, action: #selector(button1_Tap(_:)), for: .touchUpInside)
collectionCell?.secondPercent?.addTarget(self, action: #selector(button2_Tap(_:)), for: .touchUpInside)
return collectionCell!
}
#objc func button1_Tap(_ sender: UIButton) {
let firstPercent = sender
firstPercent.isSelected = true;
firstPercent.backgroundColor = UIColor.blue
secondPercent.isSelected = false;
secondPercent.backgroundColor = UIColor.white
percentage = 0.05
}
#objc func button2_Tap(_ sender: UIButton) {
let firstPercent = sender
firstPercent.isSelected = false;
firstPercent.backgroundColor = UIColor.white
secondPercent.isSelected = true;
secondPercent.backgroundColor = UIColor.blue
percentage = 0.1
}
Put your button_Tap function in your UICollectionViewCell subclass.
You can get by with just one button_Tap action. Hook both buttons to this function:
class PercentCollectionViewCell: UICollectionViewCell {
#IBOutlet weak var firstPercent: UIButton!
#IBOutlet weak var secondPercent: UIButton!
#objc func button_Tap(_ sender: UIButton) {
let buttonSelected = sender
let buttonUnselected = (sender === firstPercent) ? secondPercent : firstPercent
buttonSelected.isSelected = true
buttonSelected.backgroundColor = .blue
buttonUnselected.isSelected = false
buttonUnselected.backgroundColor = .white
percentage = (sender === firstPercent) ? 0.05 : 0.1
}
}
Then either wire the buttons up in the Storyboard or set them up like this in cellForItemAt:
collectionCell?.firstPercent?.addTarget(collectionCell!, action: #selector(PercentCollectionViewCell.button_Tap(_:)), for: .touchUpInside)
collectionCell?.secondPercent?.addTarget(collectionCell!, action: #selector(PercentCollectionViewCell.button_Tap(_:)), for: .touchUpInside)
I'm sorry, I forgot to clarify that I have the value of percentage for
each button tap functions. So I think I need a few functions. Also in
the future, there will be more buttons (up to 10).
In that case, assign your buttons to an #IBOutlet collection and assign unique tag values in the range 0...9. Connect each button to the outlet collection in the Storyboard.
#IBOutlet var buttons: [UIButton]!
Then
#objc func button_Tap(_ sender: UIButton) {
buttons.forEach { button in button.backgroundColor = .white }
sender.backgroundColor = .blue
percentage = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5][sender.tag]
}
Make sure to assign the button_Tap action to each of your buttons.

Updating button events in Swift?

I am creating a Check List app and trying to update button event which is set images itself after clicked.
Here is my code:
protocol CustomeCellDelegate {
func cell(cell: UITableViewCell, updateTheButton button: UIButton)
}
class Cells: UITableViewCell, UITextFieldDelegate {
#IBOutlet weak var checkBox: UIButton!
var buttonPressed = true
#IBAction func checkBoxAction(_ sender: UIButton) {
if buttonPressed {
sender.setImage(UIImage(named: "checkBoxB"), for: UIControlState.normal)
buttonPressed = false
} else {
sender.setImage(UIImage(named:""), for: UIControlState.normal)
buttonPressed = true
}
}
#objc func recordButtonImage(_ button: UIButton) {
cellDelegate?.cell(cell: self, updateTheButton: button) // cell notify the button that touched.
}
override func awakeFromNib() {
checkBox.addTarget(self, action: #selector(recordButtonImage(_:)), for: UIControlEvents.touchUpInside)
}
}
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, CustomeCellDelegate {
#IBOutlet weak var tableView: UITableView!
var myImages: [UIImage?]!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
myImages = Array(repeatElement(nil, count: 50))
let nib = UINib(nibName: "Cells", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "Cells")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 50
}
internal func tableView(_ tableView:UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "theCells") as? Cells
cell?.theTextField.delegate = self
cell?.cellDelegate = self
cell?.checkBox.setImage(myImages[indexPath.row], for: UIControlState.normal)
return cell!
}
// This function from protocol and it helps to update button images.
func cell(cell: UITableViewCell, updateTheButton button: UIButton) {
print("Delegate method Update Button Images.")
if let indexPath = tableView.indexPath(for: cell), let buttonImage = button.image(for: UIControlState.normal) {
myImages[indexPath.row] = buttonImage
}
}
I would like to update both events of the button that set image after checked and unchecked. Therefore, my table view can dequeue Reusable Cell and have those events updated.
But the result is just one event of button which is checked updated but not the unchecked one. The checked button still repeats whatever I do to uncheck it.
I think you don't need recordButtonImage method, you should call the delegate method from the button tapped action i.e. checkBoxAction, just like below
class Cells: UITableViewCell, UITextFieldDelegate {
#IBOutlet weak var checkBox: UIButton!
var buttonPressed = true
#IBAction func checkBoxAction(_ sender: UIButton) {
if buttonPressed {
sender.setImage(UIImage(named: "checkBoxB"), for: UIControlState.normal)
buttonPressed = false
} else {
sender.setImage(UIImage(named:""), for: UIControlState.normal)
buttonPressed = true
}
// cell notify the button that touched.
cellDelegate?.cell(cell: self, updateTheButton: button)
}
}
Also your data source method, doesn't tell the cell whether the button was pressed or not. It just sets the image but doesn't set the variable buttonPressed
internal func tableView(_ tableView:UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "theCells") as? Cells
cell?.theTextField.delegate = self
cell?.cellDelegate = self
cell?.checkBox.setImage(myImages[indexPath.row], for: UIControlState.normal)
return cell!
}
The best way to handle UIButton is using its own state.
You need to hold current state value in one array. So you can keep the state in cellForRow and other things. By default set all state to false.
In CellForRow, just put below code:
YOUR_BUTTON.isSelected = aryState[indexPath.row] as! Bool
Set image for your button
YOUR_BUTTON.setImage(UIImage(named: NORMAL_IMAGE), for: .normal)
YOUR_BUTTON.setImage(UIImage(named: SELECTED_IMAGE), for: .selected)
Just change button state when it clicked:
#IBAction func checkBoxAction(_ sender: UIButton) {
let button = sender
button.isSelected = !button.isSelected
}

How can a I limit the possibility of calling the buttonTapped function and selecting just three buttons?

Is it possible to limit the selection of buttons to just three buttons at the same time? I want users to select just 3 character traits. Right now my code is set-up in a way that tapping the button changes the image to a highlighted image. Giving the impression it is selected. I want only three buttons to be selected at once.
import UIKit
class CharacteristicsViewController: UIViewController, UINavigationControllerDelegate {
#IBOutlet weak var confidenceButton: UIButton!
#IBOutlet weak var humbleButton: UIButton!
#IBOutlet weak var creativeButton: UIButton!
#IBOutlet weak var athleticButton: UIButton!
#IBOutlet weak var loyalButton: UIButton!
#IBOutlet weak var intelligenceButton: UIButton!
#IBOutlet weak var punctualButton: UIButton!
#IBOutlet weak var kindButton: UIButton!
#IBOutlet weak var braveButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
//HIDE/SHOW NAVIGATION BAR
self.navigationController?.isNavigationBarHidden = false
//1. CONFIDENCE BUTTON SETTINGS
confidenceButton.setImage(UIImage(named: "confidentnor"), for: UIControlState.normal)
confidenceButton.setImage(UIImage(named: "confidenthigh"), for: UIControlState.selected)
confidenceButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
//2. HUMBLE BUTTON SETTINGS
humbleButton.setImage(UIImage(named: "humblenor"), for: UIControlState.normal)
humbleButton.setImage(UIImage(named: "humblehigh"), for: UIControlState.selected)
humbleButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
//3. CREATIVE BUTTON SETTINGS
creativeButton.setImage(UIImage(named: "creativenor"), for: UIControlState.normal)
creativeButton.setImage(UIImage(named: "creativehigh"), for: UIControlState.selected)
creativeButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
//4. ATHLETIC BUTTON SETTINGS
athleticButton.setImage(UIImage(named: "athleticnor"), for: UIControlState.normal)
athleticButton.setImage(UIImage(named: "athletichigh"), for: UIControlState.selected)
athleticButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
//5. LOYAL BUTTON SETTINGS
loyalButton.setImage(UIImage(named: "loyalnor"), for: UIControlState.normal)
loyalButton.setImage(UIImage(named: "loyalhigh"), for: UIControlState.selected)
loyalButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
//6. INTELLIGENT BUTTON SETTINGS
intelligenceButton.setImage(UIImage(named: "intelligentnor"), for: UIControlState.normal)
intelligenceButton.setImage(UIImage(named: "intelligenthigh"), for: UIControlState.selected)
intelligenceButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
//7. PUNCTUAL BUTTON SETTINGS
punctualButton.setImage(UIImage(named: "punctualnor"), for: UIControlState.normal)
punctualButton.setImage(UIImage(named: "punctualhigh"), for: UIControlState.selected)
punctualButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
//8. KIND BUTTON SETTINGS
kindButton.setImage(UIImage(named: "kindnor"), for: UIControlState.normal)
kindButton.setImage(UIImage(named: "kindhigh"), for: UIControlState.selected)
kindButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
//9. BRAVE BUTTON SETTINGS
braveButton.setImage(UIImage(named: "bravenor"), for: UIControlState.normal)
braveButton.setImage(UIImage(named: "bravehigh"), for: UIControlState.selected)
braveButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}
//BUTTON HIGHLIGHT FUNCTION
func buttonTapped(sender:UIButton) {
sender.isSelected = !sender.isSelected; }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
If you enclose your buttons inside a UIView, you can use this view's subviews to iterate through the buttons which will make things a little easier. There's no need to make every button an outlet however, if you choose not to, you'll have to set the .normal and .selected images in the storyboard.
Once you have a view that contains only the buttons, you can create a computed property that returns a mapped array of UIButton as well as a property that tells you how many buttons are currently selected.
// MARK: Outlets
#IBOutlet weak var traitButtonsView: UIView?
// MARK: Properties
var traitsSelected: Int {
return traitButtons.filter { $0.isSelected }.count
}
var traitButtons: [UIButton] {
return traitButtonsView?.subviews.flatMap { $0 as? UIButton } ?? []
}
// MARK: Actions
func buttonTapped(sender: UIButton) {
if traitsSelected < 3 || sender.isSelected {
sender.isSelected = !sender.isSelected
}
}
You can keep some kind of counter that increments and decrements every time buttons are tapped.
var counter = 0;
func buttonTapped(sender:UIButton) {
if sender.isSelected {
counter += 1
}
else {
counter -= 1
}
if counter > 3 {
return;
}
sender.isSelected = !sender.isSelected;
}

Selecting a custom cell activates another cell

I have a custom cell class that has an image, a few text labels(1 truncated), and a button:
class CustomTVC: UITableViewCell {
/* Outlets */
#IBOutlet weak var imageHolder: UIImageView!
#IBOutlet weak var concatenatedTitleHolder: UILabel!
#IBOutlet weak var localDateHolder: UILabel!
#IBOutlet weak var descriptionHolder: UILabel!
#IBOutlet weak var seeMoreButton: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
}
}
When the user clicks on the button, it shows the full description of the truncated text label. However, the problem I have now is when the user clicks on the button for a specific cell, it shows the full description for the cell that the user clicked, and also the full description of another cell.
I know the reason that's happening is because the tableview reuses the cell via dequeueReusableCellWithIdentifier. How would I go about implementing a function that will make sure that when a user clicks on the button for a specific cell, only that cell's full description is shown?
Code for tableview:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("customCell", forIndexPath: indexPath) as! CustomTVC
if listOfShows.count != 0 {
// Downloading and displaying picture
if let downloadPicture: UIImage = helperFunctions.downloadImage(listOfShows[indexPath.row].imageLink) {
cell.imageHolder.image = downloadPicture
}
// Enlarging / dismissing picture
cell.imageHolder.userInteractionEnabled = true
let newTapped = UITapGestureRecognizer(target: self, action: #selector(MainTVC.imagedTapped(_:)))
cell.imageHolder.addGestureRecognizer(newTapped)
// Concatenating channel + series + episode title
let concatenatedTitle = listOfShows[indexPath.row].channel + " " + listOfShows[indexPath.row].series + " " + listOfShows[indexPath.row].episodeTitle
// Converting into local date / time
let universalTime = helperFunctions.localDateAndTimeConverter(listOfShows[indexPath.row].originalAirDate)
/* Other labels */
cell.concatenatedTitleHolder.text = concatenatedTitle
cell.localDateHolder.text = universalTime
cell.descriptionHolder.text = listOfShows[indexPath.row].description
cell.seeMoreButton.tag = indexPath.row
cell.seeMoreButton.addTarget(self, action: #selector(MainTVC.buttonTapped(_:markedArray:)), forControlEvents: .TouchUpInside)
resetCellSettings(cell)
}
return cell
}
func buttonTapped(sender: UIButton, markedArray: [Bool]) {
let indexPath = NSIndexPath(forRow: sender.tag, inSection: 0)
let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomTVC
cell.seeMoreButton.hidden = true
cell.descriptionHolder.numberOfLines = 0
cell.descriptionHolder.lineBreakMode = NSLineBreakMode.ByWordWrapping
cell.descriptionHolder.sizeToFit()
}
func resetCellSettings(cell: CustomTVC) {
cell.seeMoreButton.hidden = false
cell.descriptionHolder.numberOfLines = 1
cell.descriptionHolder.lineBreakMode = NSLineBreakMode.ByTruncatingTail
cell.descriptionHolder.sizeToFit()
}
You should put buttonTapped func in CustomTVC class. And set outlet IBAction of seeMoreButton for that func when cell created.