How would I create a 'love' or 'like' button in xcode 6 (Swift)? There are a number of things I want this button to do:
1. Remain 'Liked' even if the user closes the app
2. When clicked displays a red heart instead of the previous gray one
3. Create a new cell on a UITableView from the single View Controller it is displayed on so that it shows the label (in this case) on the cell
Here is what I have so far, I am missing 1 and 3, however I also wanted to know if there are any alternatives to do number 2 from what I am doing here (self.VAR.hidden):
@IBOutlet var mealName: UILabel!
@IBOutlet var love: UIButton! //Gray heart
@IBOutlet var loveRed: UIButton! //Red heart (new image)
override func viewDidLoad() {
super.viewDidLoad()
if (self.loveRed.hidden == false) { //I want it so that it shows a gray heart unless the user has previously
self.loveRed.hidden = false //tapped the red heart to like the post. When I run the app, it always just
self.love.hidden = true //shows a the red heart.
}
else {
self.loveRed.hidden = true
self.love.hidden = false
}
}
//Outside viewDidLoad()
@IBAction func lovePressed(sender: AnyObject) { //When user taps the gray heart
self.loveRed.hidden = false //the red heart shows
self.love.hidden = true //and the gray heart hides
//Here is where I would put the code to step #3
}
@IBAction func lovePressedRed(sender: AnyObject) { //When user taps the red heart
self.loveRed.hidden = true //the red heart hides
self.love.hidden = false //and the gray heart shows
//And here is where I would put the code to remove the mealName label from step #3
}Any help would be very much appreciated and I would be very grateful.