Author Topic: Not in book Can you help  (Read 4831 times)

hcri50

  • Newbie
  • *
  • Posts: 40
    • View Profile
Not in book Can you help
« on: December 04, 2015, 09:17:52 PM »
Immutate TouchUp Button Event.
As it stands now, the Button works and I am trying to imitate the Button Action by ViewDidLoad.

import UIKit

class TestButtonProgrammicly: UIViewController {

    @IBOutlet weak var Label: UILabel!
   
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
       TurnOnLabel.sendActionsForControlEvents(.TouchUpInside)
       
    }
    @IBAction func TurnOnLabel(sender: UIButton) {
       
        Label.hidden = true
    }
}

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Re: Not in book Can you help
« Reply #1 on: December 04, 2015, 09:25:25 PM »
You can just call the method directly from viewDidLoad:

Code: [Select]
override func viewDidLoad() {
        super.viewDidLoad()
       
       self.TurnOnLabel(self.Label)
}

P.S. Typically, method names should be camel cased (turnOnLabel rather than TurnOnLabel)

All the best!
Kevin