1

画像と tapGestures で 2 つの ImageView を実装しました。ViewController を呼び出す必要がある ImageView を宣言する方法がわかりません。

私のコードは次のとおりです。

-(void) initImageViews{
self.navigationItem.title = @"Menu";
UIImage *serviceImage = [UIImage imageNamed:@"Service.png"];
self.serviceImageView = [[UIImageView alloc] initWithImage:serviceImage];
[self.serviceImageView setFrame:CGRectMake(20, 20, 48,48 )];
[self.view addSubview:self.serviceImageView];
[self.view setBackgroundColor:[UIColor blackColor]];

UIImage *industryImage = [UIImage imageNamed:@"Industry.png"];
self.industryImageView = [[UIImageView alloc] initWithImage:industryImage];
[self.industryImageView setFrame:CGRectMake(73,20,48,48)];
[self.view addSubview:industryImageView];
   UITapGestureRecognizer *singleTap =
    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];

    [self.industryImageView setUserInteractionEnabled:TRUE];
    [self.serviceImageView setUserInteractionEnabled:TRUE];
    [self.serviceImageView addGestureRecognizer:singleTap];
    [self.industryImageView addGestureRecognizer:singleTap];

 }

    - (void)handleSingleTap:(UITapGestureRecognizer *)gestureRecognizer {

NSLog(@"Tapped!");

 }

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
if ([segue.identifier isEqualToString:@"Service"]) {
    SelectOptionViewController *controller = (SelectOptionViewController*)segue.destinationViewController;
}if ([segue.identifier isEqualToString:@"Industry"]) {
    SelectOptionViewController *controller = (SelectOptionViewController*)segue.destinationViewController;
}
}

}

前もって感謝します :)

4

3 に答える 3

2

セグエを使用したくない/使用する必要がない場合は、次を使用できます。

if (i want controller A) {
    [self presentViewController:ControllerA animated:YES completion:nil];
} else if (i want controller B) 
    [self presentViewController:ControllerB animated:YES completion:nil];
}
于 2013-07-24T12:58:15.370 に答える