UITableview 从另一个类添加数据

发布于 2024-11-15 01:42:45 字数 310 浏览 9 评论 0原文

好的,我有一个 UITableView 和一个带有 UIBarButtonSystemItemAddUINavigationController ,当按下添加按钮时,它会将用户带到一个新视图一些领域。我希望能够获取用户在这些字段中输入的信息并将其显示在表视图中。我希望用户能够添加任意数量的这些项目。

现在我想起来,有点像联系人应用程序。用户填写联系人,然后当他们返回主列表时,新联系人就在那里。

最好的方法是什么?我尝试了 NSUserDefaults 和一堆数组,但这真的很混乱。谢谢。

Ok so I have a UITableView and a UINavigationController with a UIBarButtonSystemItemAdd and when the add button is pushed, it takes the user to a new view with some fields. I want to be able to get the information the user puts in these fields and display it in the table view. I want the user to be able to add as many of those items as they want.

Now that I think of it, kind of like the contacts app. The user fills out a contact and then when they go back to the main list, the new contact is there.

What is the best way to do this. I tried NSUserDefaults and a bunch of arrays, but that got really messy. Thanks.

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

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

发布评论

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

评论(3

゛时过境迁 2024-11-22 01:42:45

我能想到的几种方法来处理这个问题。最简单和最好的方法是使用视图控制器的模型演示,而不是推送它,就像 iPhone 上的联系人应用程序一样。这样您就可以使用 tableview 视图控制器访问所需的所有数据,而不是尝试来回传递它。一旦用户完成创建视图控制器,模型视图就会关闭,您可以从表视图中添加。开发人员文档:http://developer.apple.com/library/ios/ipad/#featuredarticles/ViewControllerPGforiPhoneOS/AboutViewControllers/AboutViewControllers.html%23//apple_ref/doc/uid/TP40007457-CH112-SW16

A few ways I can think of handling this. The easiest and best way would be to use a model presentation of your view controller instead of pushing to it, much like the contact app on the iPhone does. That way you can access all your data needed with your tableview view controller instead of trying to pass it back and forth. once the user is finished with the creation view controller the model view is dismiss and you can add from your tableview. Developer doc: http://developer.apple.com/library/ios/ipad/#featuredarticles/ViewControllerPGforiPhoneOS/AboutViewControllers/AboutViewControllers.html%23//apple_ref/doc/uid/TP40007457-CH112-SW16

雨的味道风的声音 2024-11-22 01:42:45

您正确使用 NSUserDefaults 了吗?像这样使用。

在一个类中:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]
[prefs setInteger:1 forKey:@"integerKey"];

在另一个类中:

 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
 NSInteger myInt = [prefs integerForKey:@"integerKey"];

//Now myInt has the value 1.

您还可以拥有 NSNotification 并传递 NSDictionary 类型:

NSDictionary *info = [NSDictionary dictionaryWithObject:@"Brad Pitt" forKey:@"User Name"];


[[NSNotificationCenter defaultCenter] postNotificationName:@"UserNameNotification" object:self userInfo:info];

然后您可以添加观察者并为相应的 Selector 编写方法。

Did you use NSUserDefaults properly ? Use like this.

In one class:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]
[prefs setInteger:1 forKey:@"integerKey"];

In another class:

 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
 NSInteger myInt = [prefs integerForKey:@"integerKey"];

//Now myInt has the value 1.

You could also have NSNotification and pass an NSDictionary type:

NSDictionary *info = [NSDictionary dictionaryWithObject:@"Brad Pitt" forKey:@"User Name"];


[[NSNotificationCenter defaultCenter] postNotificationName:@"UserNameNotification" object:self userInfo:info];

And then you could add observers and write the method for the corresponding Selector.

今天小雨转甜 2024-11-22 01:42:45

最好的方式是UIController的模型呈现风格。当用户关闭视图时,您的表视图会通过委托方法收到通知,您可以在表视图中添加该数据。

现在,如果您不想使用模型视图样式,那么您可以使用 NSUserDefault。

 Thats what I was trying to do, but the user could ultimatly enter in hunderds of data.

你不必考虑它,你应该做的是首先重置 NSUserDefault。然后将所有数据保存在 NSUserDefault 中,然后从表视图中获取该数据。

[NSUserDefaults resetStandardUserDefaults];

您还可以做的一件事是在 Delegate 中创建一个变量并在其中保存数据并在表视图中获取它。但我不建议你这样做。

The best way is model presentation style of UIController. when user dismiss the view your table view get notified by delegate method and there you can add that data in table view.

Now if you do not want to use model view style then You can use NSUserDefault.

 Thats what I was trying to do, but the user could ultimatly enter in hunderds of data.

You do not have to think about it what u should do is that you first reset the NSUserDefault. And then save all the data in NSUserDefault and then get that data from table view.

[NSUserDefaults resetStandardUserDefaults];

One thing more u can do is that make a variable in Delegate and save data in that and get it in table view. but i do not recommend you to do this.

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