简体   繁体   English

tableView reloadData不更新数据

[英]tableView reloadData does not update the data

I have 2 controllers [TableViewController, SecondViewController]. 我有2个控制器[TableViewController,SecondViewController]。 On my TableViewController I have badges and I update them from my SecondViewController, but when I update my badge count from the SecondVC it doesn't refreshes on TableVC, for this I need to change my screen or pull up my controller and just after that it refreshes my badge view. 在我的TableViewController上,我有徽章,并且从SecondViewController对其进行更新,但是当我从SecondVC更新徽章计数时,它在TableVC上不会刷新,为此,我需要更换屏幕或拉起控制器,然后再进行操作刷新我的徽章视图。

I tried this, in SecondVC when I update badge count: 我在SecondVC中更新徽章计数时尝试过此操作:

badgeCount++
TableViewController().tableView.reloadData()

Also, this: 另外,这:

badgeCounter++
dispatch_async(dispatch_get_main_queue(), { () -> Void in
    TableViewController().tableView.reloadData()
})

but in both cases it doesn't update my badge view. 但在两种情况下都不会更新我的徽章视图。 For this I need just change controllers/screens or pull up my TableVC. 为此,我只需要更改控制器/屏幕或拉起TableVC。

How can I fix this? 我怎样才能解决这个问题?

And one interesting thing, when I set the timer, which updates my TableVC every second, in this case my badge counter view updates well =/ 还有一件有趣的事,当我设置计时器时,每秒更新一次TableVC,在这种情况下,我的徽章计数器视图更新得很好= /

You can use notifications , the second view controller will notify the table view controller of bundle change. 您可以使用通知 ,第二个视图控制器将把捆绑更改通知给表视图控制器。 When you receive the notification form second view controller you can reload it. 当您收到通知表单的第二个视图控制器时,您可以重新加载它。 You also can pass the data in notification using userInfo. 您也可以使用userInfo在通知中传递数据。

Or do it with delegates where you table view controller will be the delegate of the second view controller. 或使用委托进行操作,您的表视图控制器将是第二个视图控制器的委托

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM