The approach that I used, although not ideal, has a small balance in the Notification Center, but it worked for me:
In viewDidLoad (), set the preferred content size size to 1:
override func viewDidLoad() { super.viewDidLoad()
and then, when the widget updates, it gets the real height and sets it:
var data: NSData? func updateData() { // fetch data if let data = data { let viewHeight: CGFloat // UI preperation and initialize viewHeight var preferredContentSize = CGSizeMake(0, viewHeight); } else { preferredContentSize = CGSizeMake(0, 1); } } func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)) { // Perform any setup necessary in order to update the view. // If an error is encountered, use NCUpdateResult.Failed // If there no update required, use NCUpdateResult.NoData // If there an update, use NCUpdateResult.NewData updateData() completionHandler(data != nil ? NCUpdateResult.NewData : NCUpdateResult.NoData) }
source share