0

我设置了我的应用程序,以便有多个图像选择器,每个图像选择器都有自己的图像数组。用户将按下他们希望查看的设置,选择一个图像,然后应用程序将弹回根控制器。我希望他们选择的图像作为子视图添加到我的主视图控制器中。

我在让主 ViewController 检测所选图像时遇到问题。

这是我正在尝试的方法:

在我的图像选择器中:

编辑我又遇到了问题。我添加了一个新的 viewController,因此用户将选择他们想要查看的图像数组,而不是直接查看图像数组。我改变了弹出到 viewController 的方式,因为我现在不回到 RootViewController。

- (IBAction)buttonClicked:(id)sender
{
    UIButton *button = (UIButton *)sender;
    _selectedImage = [_images objectAtIndex:button.tag];
    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    delegate.viewController.stampedImage = _selectedImage;
    NSLog(@"delegate.viewController = %@", delegate.viewController);
    NSLog(@"delegate.viewController.stampedImage = %@", delegate.viewController.stampedImage);
    NSLog(@"_selectedImage = %@", _selectedImage);
    [delegate.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}

我在这里运行了一个 NSLog 并将 selectedImage 设置为图像。

这是我在我希望图像出现的主 ViewController 中所做的事情。我在 viewWillAppear 中运行此代码:

//stampedImage = _imagePicker.selectedImage;  --- Not sure if I need this line
_stampedImageView = [[UIImageView alloc] initWithImage:stampedImage];
NSLog(@"ViewController stampedImage = %@", stampedImage);
[_stampedImageView setFrame:CGRectMake(0, 0, 80.0, 80.0)];
[_stampedImageView setMultipleTouchEnabled:YES];
[_stampedImageView setUserInteractionEnabled:YES];
[imageView addSubview:_stampedImageView];
[_stampedImageView release];

我在这里运行了一个 NSLog,但 stampedImage 总是返回为空。 stampedImage 总是返回为空

我将 stampedImage 设置为属性并且正在合成。
我还在 .h 中为我的图像选择器类设置了一个 @class。

有任何想法吗?出于某种原因,我被这个难住了。

4

0 回答 0