1

我已经用图像和 tapGestures 实现了 2 个 ImageView,这很好用,现在我想根据我点击的图像切换到另一个 ViewController。我不知道如何声明我的 ImageView 它应该调用哪个 ViewController。

所以我的代码是:

-(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
[self performSegueWithIdentifier:IdentifierForTheSegueiFromStoryBoard sender:nil];

编辑:序列必须存在于情节提要中并且必须具有标识符。

于 2013-07-24T12:53:22.817 回答
2

如果您不想/不需要使用 segues,您可以使用:

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 回答
1

Create a seague in the storyboard with the identifier.then programatically call a segue like this

[self performSegueWithIdentifier: @"myidentifier" sender: self];
于 2013-07-24T12:52:53.250 回答