在UI图像视图触摸事件IOS Storyboard上移动到下一个UIVIEW Controller

时间:2013-10-31 07:33:24

标签: ios objective-c uiview uiviewcontroller storyboard

我在滚动视图中动态添加了图像视图

  for(NSDictionary *str in slideShowImages){

    UIImageView *image = [[UIImageView alloc ] initWithFrame:CGRectMake(x, 0, 200, 150)];
    NSString *ImageURL = [str objectForKey:@"imageLink"];
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
    image.image = [UIImage imageWithData:imageData];

            UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)  ];
            singleTap.numberOfTapsRequired = 1;
            image.userInteractionEnabled = YES;
            [image addGestureRecognizer:singleTap];

    [documentory addSubview:image];

    x += image.frame.size.width+ 5;
}

documentory.contentSize = CGSizeMake(x, documentory.frame.size.height);

当图像视图触摸时调用此事件

-(void)tapDetected:{


}

我想移动到另一个uiview控制器当imageview触摸我使用故事板,因为imageview动态添加我不知道怎么做这个可以任何人帮助我

PS有一种方法可以使用

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {....} 

在这里谢谢你

2 个答案:

答案 0 :(得分:0)

如果你想以编程方式调用push segue,你可以在Interface Builder中给segue一个“storyboard id”,然后你可以:

[self performSegueWithIdentifier:"pushToMyVC" sender:self];

OR

如果您想使用导航控制器/当前视图控制器,可以使用

UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationController"];

并按下/显示您的控制器

答案 1 :(得分:0)

找到一种方法

拖动UIViewController,并在这种情况下给出一个故事板ID,我在暗示下面的动作方法之后命名为xxx

-(void)tapDetected{
    NSLog(@"single Tap on imageview");
    UIStoryboard * storyboard = self.storyboard;

    destinationViewController * detail = [storyboard instantiateViewControllerWithIdentifier: @ "xxx"];

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