如何从以前的 ViewController 更新对象?

发布于 2025-01-03 17:41:11 字数 739 浏览 1 评论 0原文

我有一个名为 searchUpdateController 的视图控制器,它有一个按钮可以推送名为 editController 的新视图控制器。在editController中有一个名为Save的按钮,它包含以下代码:



searchUpdateController = [[SearchUpdate alloc] init];
    [self.navigationController popViewControllerAnimated:YES];
    [searchUpdateController.fieldsValArray replaceObjectAtIndex:3 withObject:joinedString];
    [searchUpdateController.mainTable reloadData];
    [searchUpdateController release];

fieldsValArraysearchUpdateController中的一个NSMutableArray属性,mainTable是searchUpdateController中的tableView searchUpdateController。我想更新fieldsValArray的内容并重新加载tableView的数据。当我单击“保存”按钮时没有任何反应。我在这里缺少什么想法吗?

I have a view controller called searchUpdateController, it has a button to push a new view controller called editController. In the editController there is a button called Save and it contains the following code:



searchUpdateController = [[SearchUpdate alloc] init];
    [self.navigationController popViewControllerAnimated:YES];
    [searchUpdateController.fieldsValArray replaceObjectAtIndex:3 withObject:joinedString];
    [searchUpdateController.mainTable reloadData];
    [searchUpdateController release];

fieldsValArray is a NSMutableArray property in searchUpdateController and mainTable is the tableView in the searchUpdateController. I wanted to update the content of the fieldsValArray and reload the data of the tableView. Nothing happens when I click the Save button. Any ideas what I'm missing here?

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

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

发布评论

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

评论(2

-小熊_ 2025-01-10 17:41:11

在这里,您正在创建一个新对象,而不是在代码中使用旧对象
searchUpdateController = [[SearchUpdate alloc] init];SearchUpdateController 类设置它们 searchUpdateController。以便它指向推动 editController 的对象

Here you are creating a new objet not using the old one in the code
searchUpdateController = [[SearchUpdate alloc] init]; set them searchUpdateController from SearchUpdateController class. so that it point to that object that pushes the editController

旧城空念 2025-01-10 17:41:11

不要这样做 -> searchUpdateController = [[SearchUpdate 分配] init];
在这里,您正在创建新对象,该对象并不引用您的旧对象。

在返回到 searchUpdateController 之前,请执行以下操作:

  • 从 self.navigationController 获取倒数第二个对象。 viewControllers,只不过是 searchUpdateController
  • 现在您拥有相同的对象,因此可以根据需要更新数组数据
  • 现在有两种重新加载数据的可能性:

    1. 使用 NSNotification 并向需要重新加载表的父视图控制器发出通知
    2. 调用父类的方法来重新加载表

希望这就是您想要的。

Dont do this -> searchUpdateController = [[SearchUpdate alloc] init];
Here you are creating new object, which is not referring to your older object

Before moving back to searchUpdateController do this:

  • Get second last object from self.navigationController. viewControllers, which is nothing but the searchUpdateController
  • Now you are having the same object so update the array data whichever you want
  • Now there are two possibilities to reload data:

    1. Use NSNotification and fire a notification to parent view controller where need to reload table
    2. Call a method of parent class which will reload table

Hope this is what you want.

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