0

さて、これはここ数日間私を狂気に駆り立てています。これが簡単な修正であることを願っています。UIImageView.image にアクセスしようとしているので、後で置き換えることができます。

ここに必要なコードのみを含めると、次のようになります。

まず、ユーザーがライブラリ内の写真をクリックするたびに imageView を作成します。

// .h
@property (strong,nonatomic) UIImage *doneImage;
@property (strong,nonatomic) UIImageView *editImage;

// .m
@synthesize doneImage;
@synthesize editImage;

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(xCoordinate, yCoordinate, widthOfImage, heightOfImage)];
imgView.image = originalImage;
imgView.userInteractionEnabled = YES;
[self.mainView addSubview:imgView];

// I add gestures
longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1;
longPress.numberOfTouchesRequired = 1;
[imgView addGestureRecognizer:longPress];
}

誰かがそれらの画像のいずれかをクリックしたままにすると、これがポップアップします

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {

editImage = (UIImageView*)recognizer.view; // I declare what editImage is and now have access to what imageView is being interacted with.
doneImage = editImage.image; // I then get the image of that for later use.

if(UIGestureRecognizerStateBegan == recognizer.state) {

        popoverEditor = [[UIPopoverController alloc] initWithContentViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"popupEditor"]];
[popoverEditor presentPopoverFromRect:editImage.bounds inView:editImage permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

これにより、4 つのボタンを備えたメニューがポップアップ表示されます。次に、編集部分を起動しようとする IBAction があります。

- (IBAction)effectsEditorButton:(id)sender { 

// editImage is my imageView

if (editImage == nil) {
    NSLog(@"imageView was nil wtf");
} else {
    [self performSelector:@selector(editImageWithEffects:)];
   }
}

私の画像ビューは常にゼロです。どういうわけかそれへの参照を取得する必要があります。タグを試してみましたが、この時点で値を保持できないようです。

どんな助けでも大歓迎です。ありがとう!

4

1 に答える 1

0

コードを省略していますか?ここにあるものに基づいて、editImageはどこにも宣言されていないため、常にnullになります(おそらく、Interface Builderで表示できないものがありますか?)。

ポップオーバーからViewControllerにリンクする方法が必要です。これを行う一般的な方法は、ポップオーバーコントローラーから戻るときに完了ブロックを使用するか、「メイン」VCをポップオーバーの弱いプロパティとして設定することです。

于 2012-10-17T21:08:44.163 に答える