我的問題是,我得到本地通知,然後告訴我的一個VC更新其UITableView。但是,tableview不會重新加載。我知道所有if語句檢查都通過並且正在運行代碼。這原本讓我相信這是一個線程問題,所以我在dispatch_async(dispatch_get_main_queue(), {})
中包裝了重新加載。但是這也不起作用。所以如果不是線程問題是什麼呢?什麼可能導致這個?我在這裏做錯了什麼?無法從didReceiveLocalNotification重新加載UITable
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
if notification.alertBody != nil{
if notification.alertBody!.hasSuffix("starting") || notification.alertBody!.hasSuffix("ending"){
dispatch_async(dispatch_get_main_queue(), {
if topMostContoller() is SecondViewController{
let vc = self.tabBarController?.getVC(.Attendance) as! SecondViewController
vc.myTableView?.reloadRowsAtIndexPaths((vc.myTableView?.indexPathsForVisibleRows)!, withRowAnimation: .None)
// vc.myTableView?.reloadData() <- this doesn't work either
}
})
}
}
}
編輯:
func getVC(vc:tabBarVC)->UIViewController?{
switch vc{
case .Home:
return fullTabBar[0]
case .Attendance:
return fullTabBar[1]
case .Location:
return fullTabBar[2]
case .Sign:
return fullTabBar[3]
case .Settings:
return fullTabBar[4]
}
}
凡fullTabBar中的TabBar的viewDidLoad
設置。
fullTabBar = self.viewControllers as [UIViewController]!
self
是使用TabBar實例。
你能打印調用reload之前'vc.myTableView'的值? –
@PhillipMills'vc =可選(; layer = ; contentOffset :{0,0}; contentSize:{768,2728}>)' –
boidkan
其他代碼,例如爲UITableView填充數據數組,運行但實際上並不會影響它們應該使用的對象。我忽略了這個問題儘可能簡單化。 – boidkan