2015-08-31 19 views
6

今天的小工具被添加到今日視圖時正確繪製。但是,如果用戶稍後回來,viewDidLoad函數不會被調用,並且它顯示陳舊的數據。應該每次調用viewDidLoad?是否有iOS 9/Xcode 7 beta 6的bug?iOS 9今日小工具不會調用viewDidLoad

編輯: 增加了widgetPerformUpdateWithCompletionHandler不調用。我有斷點設置和打印功能

func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)) { 
    print("in widgetPerformUpdateWithCompletionHandler") 
    fetch() 

    completionHandler(NCUpdateResult.NewData) 
} 
+0

我從來沒有使用過小部件,但通常在每次顯示屏幕時調用'viewDidAppear','viewDidLoad'只在最初加載視圖時調用。 –

+0

您是不是使用'widgetPerformUpdateWithCompletionHandler:'參見[這裏](https://developer.apple.com/library/ios/documentation/NotificationCenter/Reference/NCWidgetProviding_Protocol/index.html#//apple_ref/occ/intfm/NCWidgetProviding/ widgetPerformUpdateWithCompletionHandler :) – soulshined

+3

我有同樣的問題。每次顯示小部件時都會調用「widgetPerformUpdateWithCompletionHandler」。 iOS9調用這個方法要少得多。但是我沒有找到任何關於這個改變的文件。 –

回答

0

發佈我自己的答案,但想在這個代碼的討論 - 它應該是有或如何正確地做到這一點?我們在此方法中,並刪除它的小部件開始當你在屏幕上滾動的窗口小部件關閉並返回到正常工作

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) 
{ 

    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) 

    if let safeCoordinator = coordinator as UIViewControllerTransitionCoordinator? 
    { 
     print("coordinator != nil") 
     safeCoordinator.animateAlongsideTransition({ context in 
      self.tableView.frame = CGRectMake(0, 0, size.width, size.height) 
      }, completion: nil) 

    } 
    else 
    { 
     print("coordinator == nil") 
    } 
} 
+0

這段代碼看起來像是在嘗試調整表格視圖的大小,以響應其他改變視圖高度的其他內容。那是什麼?如果您使用的是自動佈局,則您的表格視圖應調整大小以適應其顯示的單元格數量。否則,您可以設置[preferredContentSize](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instp/UIViewController/preferredContentSize)來指定您想要的高度。 –

+0

@ChristopherPickslay Apple不禁止使用preferredContentSize嗎? – Supertecnoboff

+1

@Supertecnoboff不是我所知道的:'如果你不使用Auto Layout,你可以使用UIViewController屬性preferredContentSize來請求widget的高度。'https://developer.apple.com/library/ios /documentation/General/Conceptual/ExtensibilityPG/Today.html#//apple_ref/doc/uid/TP40014214-CH11-SW5 –

5

,同一個控制器實例將用於短時間內被重複使用(出現在我的測試中約30秒),並且viewDidLoadwidgetPerformUpdateWithCompletionHandler:將不會被調用。

但是,每次顯示小部件時都會調用viewWillAppearviewDidAppear

+0

這也解決了我的問題 – Rand

+0

謝謝是的,我切換到viewDidAppear現在一切正常,謝謝: ) – Supertecnoboff

相關問題