选择第一行时,数据未加载到详细视图控制器

发布于 2024-11-01 22:53:08 字数 495 浏览 1 评论 0原文

当我启动相关应用程序时,我从 plist 派生的数组中加载一个表。在 didSelectRowAtIndexPath 中,我将数组中的值分配给详细视图控制器中的子视图,然后将详细视图控制器推入堆栈,但是在运行应用程序时,第一次我从表中选择任何行,数组中的数据不会出现在我的详细视图控制器的子视图/字段中。然后,我单击返回表视图,重新选择行,然后将数据加载到详细视图控制器中。

在表视图控制器 didSelectRowAtIndexPath 方法中,我执行以下操作,其中 xLabel 是推送视图控制器 xib 中的 UILabel 子视图:

self.detailViewController.xLabel.text = [[[xArray objectAtIndex: indexPath.section] objectForKey:@"xDesc"] objectAtIndex:indexPath.row];

我需要做什么才能在第一次选择行时显示数据?

When I launch the app in question I load up a table from an array derived from a plist. In didSelectRowAtIndexPath I assign values from the array to sub views in detail view controller and then push the detail view controller onto the stack, but when running the app, the first time I select any row from the table, data from the array does not appear in my detail view controller's subviews/fields. I then click back to the table view, re-select the row and the data then loads in the detail view controller.

In the table view controller didSelectRowAtIndexPath method I do the following where xLabel is the UILabel sub view in the pushed view controller's xib:

self.detailViewController.xLabel.text = [[[xArray objectAtIndex: indexPath.section] objectForKey:@"xDesc"] objectAtIndex:indexPath.row];

What do I need to do to have the data appear the first time a row is selected?

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

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

发布评论

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

评论(2

我的黑色迷你裙 2024-11-08 22:53:08

我认为这是行不通的,因为第一次选择一行时,详细视图控制器不在内存堆栈中,因此您无法在前一个视图控制器中调用标签的 setText 方法。第二次它工作,因为它在内存中,所以你可以调用其组件的 set 方法。我想说的是,当您将详细视图控制器推入堆栈时,只需在此处设置一串详细视图控制器(该字符串应该是详细视图控制器的属性),然后在详细视图控制器的 viewDidLoad 方法中设置标签的文本到这个字符串。

I think this is not working because first time when you select a row your detail view controller is not there in memory stack, so you can not call setText method of a label in previous view controller. Second time its working because its there in memory so you can call set method to its component. What i want to say it that when you are pushing detail view controller in stack just set a string of detail view controller here (this string should be property of detail view controller) and then in detail view controller's viewDidLoad method set the text of your label to this string.

拥醉 2024-11-08 22:53:08

如果我理解正确的话,第一次没有 xLabel 对象,因为它将在 UIViewController 被“加载”时创建。因此,当您尝试设置文本值时,它不会加载到标签中,因为没有标签。当标签是从第一次尝试创建时,后续尝试就会起作用。无论如何,如果您需要与详细视图共享一些数据,请将其存储在字典或其他对象中,而不是直接将其从当前控制器分配给视图。

If i understood you correctly, there is no xLabel object the first time around as it will be created when the UIViewController is being "loaded". So, when you try to set the text value, it isnt loaded into the label, as there is no label. Subsequent attempts work as the label is created from the first attempt. Anyways, if you need to share some data with the detail view, store then in a dictionary or some other object rather than just assigning it directly to the view from the current controller.

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