从另一个视图控制器与另一个视图控制器交互
当我单击按钮时,我希望我的视图控制器检查另一个视图控制器上是否有图像。但到目前为止,即使有图像,模拟器也不会执行循环。
代码:
- (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];
}
谢谢, 普拉文
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.
Code:
- (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];
}
Thanks,
Praveen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在创建
iPhotoViewController
的新实例,这意味着您要使用的图像必须在 nib 文件中可用。在 nib 文件中可用意味着它在您的项目中可用,因此创建一个新的 iPhotoViewController 只是为了查看该图像是否存在似乎有点奇怪。您加载图像的地方是否已经存在此
iPhotoViewController
的实例?如果是这样,这就是您需要检查的实例。但也许您正在测试一些东西并在笔尖中设置了图像,只是想确保它有效。在这种情况下,未设置
photo.mainView.image
的原因是因为您仅创建了视图控制器,但尚未从笔尖加载和设置视图。要伪造这一点,您需要在检查图像是否已设置之前访问控制器的view
属性。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 newiPhotoViewController
just to see if that image is there seems a bit strange.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.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 theview
property of the controller before checking if the image is set.您是否
在 .h 和
.m 中都定义了?
did you define both
in your .h and
in your .m ?