0

コントローラで void touchesbegan メソッドを宣言しましたが、機能しません! どうしてか分かりません。クリックして次のコントローラーに移動する予定の画像ビューがあります。だから私はタッチ開始メソッドを設定しました。私はxibファイルの画像ビューをリンクしましたが、画像をクリックすると. 何も起こりません。助けてください、ありがとう。

ViewController.h

#import <UIKit/UIKit.h>

@interface imageViewViewController : UIViewController
{
    IBOutlet UIImageView *testing;
}
@property(nonatomic, retain) IBOutlet UIImageView *testing;

@end

ViewController.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject];

    if(touch.view == testing)
    {
        TestViewController *testviewcontroller = [[TestViewController alloc]initWithNibName:nil bundle:nil];

        [self.navigationController pushViewController:testviewcontroller animated:YES];
    }
}

@end

PS

ここで、タップジェスチャを使用した別の方法を試しました。testing は私の画像ビューの名前です。ご覧のとおり、imagedidtapped メソッドで ns ログをコメントアウトしています。それはその時点まで機能します。ただし、別のページに移動しようとすると失敗します。

- (void)viewDidLoad
{


    UITapGestureRecognizer *tapRecognizer;
    [testing setTag:0]; 
    [testing setUserInteractionEnabled:TRUE];
    tapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewDidTapped:)] autorelease];
    tapRecognizer.numberOfTapsRequired = 1;
    [testing addGestureRecognizer:tapRecognizer];
    [self.view addSubview:testing];
    [testing release];





    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}



- (void)imageViewDidTapped:(UIGestureRecognizer *)aGesture {
    UITapGestureRecognizer *tapGesture = (UITapGestureRecognizer *)aGesture;

   UIImageView *tappedImageView = (UIImageView *)[tapGesture view];

    switch (tappedImageView.tag) {
        case 0:
            //NSLog(@"UIImageView 1 was tapped");
            [self navigate];

            break;
        case 1:
            NSLog(@"UIImageView 2 was tapped");
            break;
        default:
            break;
    }
}



-(void)navigate
{
    TestViewController *testviewcontroller = [[TestViewController alloc]initWithNibName:nil bundle:nil];

    [self.navigationController pushViewController:testviewcontroller animated:YES];
}
4

1 に答える 1