2

I have three files:

  1. SummaryView.xib -> containing the outline of my view
  2. SummaryView.swift -> controller for the view above with outlets defined for the subviews (such as the button discussed in this question)
  3. TodayViewController.swift -> controller for the "Today" widget

I am loading the SummaryView.xib within my TodayViewController using this code:

var summaryView: SummaryView!
summaryView = UINib(nibName: "SummaryView", bundle: NSBundle.mainBundle()).instantiateWithOwner(SummaryView.self, options: nil)[0] as! SummaryView

The xib contains a button with its outlet defined in the controller SummaryView.swift:

@IBOutlet weak var openAppButton: UIButton!    
@IBAction func openAppButtonClicked(sender: AnyObject) {
    let url = NSURL(string: "MyApp://")
    sender.extensionContext!!.openURL(url!, completionHandler: nil)
}

Unfortunately, this function is never called on button click. After that I defined an additional target in the controller of the Today Widget:

summaryView.openAppButton.userInteractionEnabled = true
summaryView.openAppButton.addTarget(self, action:#selector(TodayViewController.openApp(_:)), forControlEvents: UIControlEvents.TouchUpInside)

together with the method

func openApp(sender: AnyObject) {
    let url = NSURL(string: "MyApp://")
    sender.extensionContext!!.openURL(url!, completionHandler: nil)
}

but this methods is also not called.

The click does trigger something though, as I can see the following entries in the console:

2016-09-21 14:51:45.667049 My App Widget[7546:1001683] subsystem: com.apple.UIKit, category: GestureEnvironment, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
2016-09-21 14:51:45.667669 My App Widget[7546:1001683] subsystem: com.apple.UIKit, category: GestureExclusion, enable_level: 0, persist_level: 0, default_ttl: 1, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0

What am I missing?

Cheers

AntonSack
  • 1,021
  • 2
  • 25
  • 47

0 Answers0