iPhone Dev:从子控制器和 TabBar 中的另一个控制器重新加载表视图的数据

发布于 2024-07-22 07:40:21 字数 285 浏览 5 评论 0原文

我正在实现一个笔记管理器应用程序,它在 tabBar 中有一个 tableView,其中显示其笔记的主要信息。 访问一个注释时,您可以编辑其属性。 在 tabBar 的一键中,您可以选择注释在 tableView 中的显示方式。

我遇到的问题是,我也不知道如何从子控制器或 tabBar 的其他控制器重新加载数据。 我不知道如何从它们引用 tableView,所以我可以使用 reloadData 从它们更新 TableView 的信息。

我对 iPhone 开发还很陌生......任何帮助将不胜感激。

I'm implementing a notes manager application which has a tableView in a tabBar where the main information of its notes is displayed. When accessing to one note, you can edit its properties. In one button of the tabBar you can choose the way the notes are displayed in the tableView.

The problem I have is that I don't know how to reload the data from a child controller or from the other controller of the tabBar, either. I don't know how to refer to tableView from them so I can use reloadData to update the information of the TableView from them.

I'm quite new in iPhone development... any help will be really appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

坏尐絯℡ 2024-07-29 07:40:21

您应该尝试NSNotificationCenter

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomething:) name:@"doSomethingNotification" object:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"doSomethingNotification" object:nil];

You should try NSNotificationCenter.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomething:) name:@"doSomethingNotification" object:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:@"doSomethingNotification" object:nil];
长不大的小祸害 2024-07-29 07:40:21

将表更新代码放在 viewWillAppear: 而不是 viewDidLoad 中 - 这样每次从子控制器返回父控制器时,数据都会重新加载。

Put your table updating code in viewWillAppear: in stead of viewDidLoad - that way each time you go back to your parent controller from the child controller, the data get reloaded.

月依秋水 2024-07-29 07:40:21

MVC 模式就会有所帮助。

只要您不断使用所需的信息更新模型并且您的控制器从该模式进行更新, 当您在视图之间向后滑动时,您最终会自动更新视图。

这样您就可以调用重新加载数据方法,它们将得到更新。

[tableviewController.tableview reloadData]; 

这是您访问重新加载数据消息的方式。

the MVC pattern will help here,

as long as you keep updating your model with the information that is needed and your controllers are updating from that modal. As you flick back between the views you end up automatically updating the views.

that way you can call your reload data methods and they will get updated.

[tableviewController.tableview reloadData]; 

is how you access the reload data message.

亢潮 2024-07-29 07:40:21

我在处理原型单元时遇到了同样的问题。 奇怪的是,我很确定我做的一切都是对的。

然后我开始思考XCode是否有什么问题。 所以我清理了所有内容,重新启动 XCode,但它仍然抱怨。

最后,我尝试重做我最近对故事板的更改,即添加一个 tableviewcell 类并将其与我的所有 ui 控件连接起来。 终于它不再抱怨了。

我不认为这个错误是由你的代码或其他什么引起的,我在 iOS 5 中遇到了几个奇怪的错误。对了,它仍在测试中并且有很多错误。

不管怎样,故事板很棒,我会努力习惯它,它描绘了应用程序的大局,并且很容易处理不同视图之间的关系。 另外我真的很喜欢他的prepareforsegue方法。

好的祝你好运。

I came to the same problem while dealing with prototype cell. Weird I was quite sure I did everything right.

Then I started thinking if there's anything wrong with XCode. So I cleaned up everything, restarted XCode and it still complained.

At last, I tried to redo my most recent changes to the story board which is add a tableviewcell class and hooked it up with all my ui controls. Finally it stopped complaining.

I don't think this error is caused by your code or something, I've came to several weird errors in iOS 5. Right it's still testing and has lots of bugs.

Anyway, storyboard is great and I will try to get used to it, it draws the big picture of your app and is easy to handle the relationship between different views. Plus I really like his prepareforsegue method.

OK Good Luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文