M13Checkbox set Mixed CheckState on click - ios

I try to implement a M13Checkbox in tableViewCell.
I implemented a method responding to "ValueChanged" event but if I call sender.setCheckState(.Mixed, animated: false) in this method, the display of the checkbox is .Checked.
However if I do print(sender.checkState) the state of the checkbox is .Mixed.
Anything that i'm missing ? Do i use the write event?
Thanks for your help !
edit:
Event present in OptionsViewController:
#IBAction func optionCheckChange(sender: M13Checkbox) {
let rowPoint = sender.convertPoint(sender.frame.origin, toView: self.optionsTableView)
let indexPath = self.optionsTableView.indexPathForRowAtPoint(rowPoint)
sender.setCheckState(.Mixed, animated: false)
print(sender.checkState)
}
OptionTableViewCell code:
import UIKit
import M13Checkbox
class OptionTableViewCell: UITableViewCell {
// MARK: Properties
#IBOutlet weak var checkbox: M13Checkbox!
#IBOutlet weak var label: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}

Related

Calling a function that will hide a button from another class - swift

I'm trying to create an IMDB-ish movie application where when the user doesn't login and presses a Skip button, a Favorite (add a movie to favourites) button would dissappear.
The LandingViewController is where the Skip button is and the MovieTableViewCell is where all the data is presented.
What must I do so that the hide action will work inside the function? what's the logic behind this? what am I missing?
Kindly check the below comments in the code. thanks !
import UIKit
class LandingViewController: UIViewController {
#IBOutlet weak var skipButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func didTapSkip(_ sender: Any) {
MovieTableViewCell().hideButton()
}
import UIKit
class MovieTableViewCell: UITableViewCell {
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet weak var ratingLabel: UILabel!
#IBOutlet weak var languageLabel: UILabel!
#IBOutlet weak var releaseYearLabel: UILabel!
#IBOutlet weak var posterImage: UIImageView!
#IBOutlet weak var favoriteButton: UIButton?
override func awakeFromNib() {
super.awakeFromNib()
favoriteButton?.isHidden = true // works here for some reason
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
func hideButton() {
favoriteButton?.isHidden = true // doesn't work and If I unwrap it, the app will crash, because it will find the buttton as NIL for some reason
print("hidebutton") // the print works so the function works when the skip is pressed
}
Try using NSUserDefaults
In LandingViewController
#IBAction func didTapSkip(_ sender: Any) {
UserDefaults.standard.set(true, forKey: "didSkip")
}
In MovieTableViewCell
override func awakeFromNib() {
super.awakeFromNib()
if UserDefaults.standard.bool(forKey: "didSkip") {
favoriteButton?.isHidden = true
} else {
favoriteButton?.isHidden = false
}
}

Getting Nil While Trying to Set Class Label Property | UITableView

I keep getting unexpectedly found nil while unwrapping an Optional value when I run this code.
What I am trying to do is get the first property in an array of objects so I use .map to get the first property which is "workoutName"
Then I try to set the label in the CellData class to this value but keep getting that it found nil.
I appreciate all help I can get.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var workoutName = workouts.map { $0.workoutName }
let cell = CellData()
cell.workoutNameLabel.text! = workoutName[indexPath.row]
return cell
}
Cell Data Class
import UIKit
class CellData: UITableViewCell {
#IBOutlet weak var workoutNameLabel: UILabel!
#IBOutlet weak var numberOfSetsNumberLabel: UILabel!
#IBOutlet weak var numberOfRepsNumberLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
I would set class variable into CellData class and set it in awakeFromNib since awakeFromNib won't happen before the cellForRow is finished, so you can be almost 100% sure that the label will be nil.. try this:
import UIKit
class CellData: UITableViewCell {
//someLableValue string
var labelValueText: String?
#IBOutlet weak var workoutNameLabel: UILabel!
#IBOutlet weak var numberOfSetsNumberLabel: UILabel!
#IBOutlet weak var numberOfRepsNumberLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
workoutNameLabel.text = labelValueText
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
then you jsut set the variable labelValueText in cellForRowMethod in UITableViewController class

How can I pass the value from a DatePicker Label to my TableView

I've a datePicker which stores the value in a variable named dateLabel and in another VC, I have a tableView which holds a labelText to show my dateLabel. I'm using this code, but gives me a SIGABRT.
This is the code of my VC which has the datePicker and dateLabel
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var Dest:CustomCell=segue.destination as! CustomCell
Dest.LabelText=dateLabel.text!
}
CustomCell is my Class which has the code
class CustomCell: UITableViewCell {
var LabelText = String()
override func awakeFromNib() {
super.awakeFromNib()
dateLabel.text=LabelText
}
#IBOutlet weak var dateLabel: UILabel!
#IBOutlet weak var checkTest: BEMCheckBox!
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}

Swift customize table view cell unresolved identifier

I want to customize a table view cell, so I created a new file like the following and did necessary steps mentioned in https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson7.html
DetailTableViewCell.swift:
import UIKit
class DetailTableViewCell: UITableViewCell {
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet weak var contentLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
But when I write var details =Detail(), it will report Use of unresolved identifier 'Detail'.
WHY? I just follow the tutorial.
class CurrentViewController: UIViewController{
var details=[Detail]()
...
}
You did not define Detail model object.
You have to work with this first:

Custom cell class and TableViewController

My problem:
I can not communicate properly to the custom cell class with the
table view controler.
I have a button on the cell, I need to write a function and assign
the action of this button in the classroom and not in the class
TableViewController CustomCell.
Here is my code:
CustomCellClass:
class CustomCategoryTableViewCell:UITableViewCell {
#IBOutlet weak var customButton: UIButton!
#IBOutlet weak var title: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
println("Cell is selected.")
}
#IBAction func searchChild(sender: AnyObject) {
println("Tap button ")
}
}
And TableViewController:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellCustom:CustomCategoryTableViewCell = tableView.dequeueReusableCellWithIdentifier("CustomCellCategory") as CustomCategoryTableViewCell
cellCustom.customButton.tag = indexPath.row
cellCustom.title.text = myArray[indexPath.row].nameCategory)
return cellCustom
}
Thanks.
EDIT: I need to write the action in the class TableViewController, because I do TableView.reloadData ()
my nib register:
var nib = UINib(nibName: "CategoryCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "CustomCellCategory")
Check this tutorial
http://www.weheartswift.com/swifting-around/
You need to register nib and also your cellForRowAtIndexPath is wrong...

Resources