在倒带时自动重新加载TableViewController

编程入门 行业动态 更新时间:2024-10-24 08:24:05
本文介绍了在倒带时自动重新加载TableViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个应用程序,它从一个tableViewController开始,它加载并显示存储在Realm数据库中的数据。我有它所以我可以在一个单独的场景中在我的Realm数据库中创建一个新条目,并且保存按钮展开会回到初始tableView。

I am working on an app where it starts out at a tableViewController which loads and displays data stored in a Realm database. I have it so I can create a new entry in my Realm database in a separate scene and the save button unwind segues back to the initial tableView.

我当前有它所以tableViewController会在下拉时重新加载tableView(我在这里学到的东西,第二个回答)但是如果tableView在展开时自动重新加载它自己,我会更好,显示我的数据库中的所有数据,包括我的新条目。有人可以指导我一个教程,教我如何做到这一点。

I current have it so the tableViewController will reload the tableView on pull down (something I Learned here, second answer down) but I would be better if the tableView would reload its self automatically upon unwind, displaying all the data in my database, including my new entry. Could someone please direct me to a tutorial that will teach me how this is done.

其他信息:我的应用程序嵌入在导航控制器中。保存按钮位于底部工具栏。

Additional info: My app is embedded in a navigation controller. The save button is located the bottom tool bar.

推荐答案

您可以使用 NSNotification 为此。

首先在 tableViewController 中将此添加到 viewDidLoad中方法:

First of all in your tableViewController add this in your viewDidLoad method:

override func viewDidLoad() { super.viewDidLoad() NSNotificationCenter.defaultCenter().addObserver(self, selector: "refreshTable:", name: "refresh", object: nil) }

这会调用你班上的一个方法:

And this will call one method from your class:

func refreshTable(notification: NSNotification) { println("Received Notification") tableView.reloadData() //reload your tableview here }

所以也要添加这个方法。

So add this method too.

现在在你的下一个视图控制器中添加新的数据到数据库中添加这个 unWindSegue 功能:

Now in your next view controller where you add new data into data base add this in you unWindSegue function:

NSNotificationCenter.defaultCenter().postNotificationName("refresh", object: nil, userInfo: nil)

Hope它会帮助

更多推荐

在倒带时自动重新加载TableViewController

本文发布于:2023-07-11 09:17:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   倒带时   TableViewController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!