我的问题是,我得到本地通知,然后告诉我的一个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