与来自另一个视图控制器的视图控制器交互 [英] Interact with a view controller from another view controller
问题描述
我希望我的视图控制器在我点击按钮时检查另一个视图控制器上是否有图像。但是现在甚至有一个图像模拟器不执行循环。
I want my view controller to check if there is an image on another view controller when i click a button. But as of now even there is an image the simulator does not execute the loop.
代码:
- (IBAction)buttonClicked:(id)sender {
iPhotoViewController *photo = [[iPhotoViewController alloc] initWithNibName:@"iPhotoViewController" bundle:nil] ;
if (photo.mainView.image)
{
but = (UIButton *) sender;
self.selectedImage = [_images objectAtIndex:but.tag];
iPhoto2AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navController popViewControllerAnimated:YES];
[photo release];
}
感谢您,
Praveen
Thanks, Praveen
推荐答案
您正在创建 iPhotoViewController
的新实例,这意味着您要使用的映像必须可用nib文件。并且在nib文件中可用意味着它在您的项目中可用,因此创建一个新的 iPhotoViewController
只是看看这个图像是否有似乎有点奇怪。
You are creating a new instance of iPhotoViewController
which means that the image you want to use must be available in the nib file. And being available in the nib file means that it is available in your project so creating a new iPhotoViewController
just to see if that image is there seems a bit strange.
这个 iPhotoViewController
的实例可能已经加载了图像吗?如果是这样,你需要检查的实例。
Is there perhaps already an instance of this iPhotoViewController
somewhere where you have a loaded an image? If so that is the instance you need to check.
但也许你正在测试的东西,并设置了一个图像在笔尖,只是想确保它的工作。在这种情况下,原因 photo.mainView.image
未设置是因为您只创建了视图控制器,但视图尚未从nib加载和设置。要伪造这个,您需要访问控制器的视图
属性,然后再检查是否设置了映像。
But perhaps you are testing things and have set an image in the nib and just want to make sure it works. In that case, the reason photo.mainView.image
is not set is because you have only created the view controller but the view as not yet been loaded and setup from the nib. To fake this you need to access the view
property of the controller before checking if the image is set.
iPhotoViewController *photo = [[iPhotoViewController alloc] initWithNibName:@"iPhotoViewController" bundle:nil] ;
[photo view];
if (photo.mainView.image) {
// continue as before
这篇关于与来自另一个视图控制器的视图控制器交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!