将数据发送到 iPhone 上的模态视图控制器时出现问题
所以我有一个主视图,上面有一些图像,当有人触摸其中一张图像时,该图像将向该主视图返回一个 ID 号,然后该视图将呈现一个模态视图控制器来显示更大版本的这个图像。但是我目前的做法是,模态控制器上的函数在加载 NIB 之前到达那里,因为当(在该函数中)我告诉它更改某些 IB 标签的文本时,它们是 NULL。然而,当我按下一个调用函数来执行相同操作的按钮时,它就可以了。这就是我现在正在做的事情:
在呈现数据时将数据发送到模式视图控制器的最佳方式是什么?非常感谢!
<代码> - (void)photoViewWasTouchedWithID:(int)imgID {
[self presentModalViewController:singlePhotoView animated:YES];
[singlePhotoView showImageWithID:imgID];
}
So I've got one main view with some images on it, and when someone touches one of the images, the image will return an ID number to this main view and then this view will present a modal view controller to display a larger version of this image. But the current way I'm doing it, the function on the modal controller is getting there before the NIB is loaded or something, because when (in that function) i tell it to change the text of some IB labels they are NULL. However, when I, say, press a button that calls a function to do the same it does it just fine. Here's what I'm doing now:
What is the best way to send data to a modal view controller while presenting it? Thanks so much!
- (void)photoViewWasTouchedWithID:(int)imgID {
[self presentModalViewController:singlePhotoView animated:YES];
[singlePhotoView showImageWithID:imgID];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要在 showImageWithID: 中进行视图对象操作,而是将参数存储到成员变量中。然后在 viewWillAppear 中进行设置工作,并且您的视图对象应该被实例化。
Instead of doing the view object manipulation in showImageWithID:, store the parameter into a member variable. Then do your setup work in viewWillAppear, and your view objects should be instantiated.