如何从以前的 ViewController 更新对象?
我有一个名为 searchUpdateController
的视图控制器,它有一个按钮可以推送名为 editController 的新视图控制器。在editController中有一个名为Save的按钮,它包含以下代码:
searchUpdateController = [[SearchUpdate alloc] init];
[self.navigationController popViewControllerAnimated:YES];
[searchUpdateController.fieldsValArray replaceObjectAtIndex:3 withObject:joinedString];
[searchUpdateController.mainTable reloadData];
[searchUpdateController release];
fieldsValArray
是searchUpdateController
中的一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里,您正在创建一个新对象,而不是在代码中使用旧对象
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 themsearchUpdateController
fromSearchUpdateController
class. so that it point to that object that pushes theeditController
不要这样做 -> searchUpdateController = [[SearchUpdate 分配] init];
在这里,您正在创建新对象,该对象并不引用您的旧对象。
在返回到 searchUpdateController 之前,请执行以下操作:
现在有两种重新加载数据的可能性:
希望这就是您想要的。
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:
Now there are two possibilities to reload data:
Hope this is what you want.