从另一个视图控制器与另一个视图控制器交互

发布于 2024-10-05 16:04:27 字数 596 浏览 4 评论 0原文

当我单击按钮时,我希望我的视图控制器检查另一个视图控制器上是否有图像。但到目前为止,即使有图像,模拟器也不会执行循环。

代码:

- (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 技术交流群。

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

发布评论

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

评论(2

生活了然无味 2024-10-12 16:04:27

您正在创建 iPhotoViewController 的新实例,这意味着您要使用的图像必须在 nib 文件中可用。在 nib 文件中可用意味着它在您的项目中可用,因此创建一个新的 iPhotoViewController 只是为了查看该图像是否存在似乎有点奇怪。

您加载图像的地方是否已经存在此 iPhotoViewController 的实例?如果是这样,这就是您需要检查的实例。

但也许您正在测试一些东西并在笔尖中设置了图像,只是想确保它有效。在这种情况下,未设置 photo.mainView.image 的原因是因为您仅创建了视图控制器,但尚未从笔尖加载和设置视图。要伪造这一点,您需要在检查图像是否已设置之前访问控制器的 view 属性。

iPhotoViewController *photo = [[iPhotoViewController alloc] initWithNibName:@"iPhotoViewController" bundle:nil] ;

[photo view];
if (photo.mainView.image) {
// continue as before

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.

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 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
万人眼中万个我 2024-10-12 16:04:27

您是否

@property(nonatomic, retain) UIImage * image;  // (or UIImageView *)

在 .h 和

@synthesize image;

.m 中都定义了?

did you define both

@property(nonatomic, retain) UIImage * image;  // (or UIImageView *)

in your .h and

@synthesize image;

in your .m ?

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