简体   繁体   English

ios-如何将对象传递给手势识别器选择器

[英]ios - how to pass object to gesture recognizer selector

on the mainViewController, i'm displaying different DOT objects on UIImageView. 在mainViewController上,我在UIImageView上显示了不同的DOT对象。 Imagine it like tagging a photo. 想象一下,就像给照片加标签一样。 Each DOT is an object which contains information such as ID, title, locationX, locationY. 每个DOT是一个对象,其中包含诸如ID,标题,locationX,locationY之类的信息。 When a DOT is tapped, it is presented with a InfoViewController which I would like to display the DOT object information. 轻按DOT时,会显示一个InfoViewController,我想显示DOT对象信息。 How should I go about doing this? 我应该怎么做呢?

here are some snippets on how i create gesture recognizer for each DOT object: 以下是一些有关如何为每个DOT对象创建手势识别器的摘要:

-(void)viewDidAppear:(BOOL)animated
{

    NSArray *allDotItems = [[DotStore getInstance] allDotItems];
    for(DotStore *item in allDotItems)
    {
        NSLog(@"ID:%@", item.ID);
        NSLog(@"Title:%@", item.title);
        NSLog(@"LocationX:%f", item.locationX);
        NSLog(@"LocationX:%f", item.locationY);

        // Create the DOT
        CGRect viewFrame = CGRectMake(item.locationX, item.locationY, DRAW_RECT_WIDTH, DRAW_RECT_HEIGHT);
        self.abstractDotView = [[DOTAbstractDotView alloc] initDot:viewFrame];
        [[self imageView] addSubview:self.abstractDotView];

        // Register gesture reconginzer for tap within the Dot
        UITapGestureRecognizer *singleTapOnDot =
        [[UITapGestureRecognizer alloc] initWithTarget:self
                                                action:@selector(handleSingleTapWithinDot:)];
        [self.abstractDotView addGestureRecognizer:singleTapOnDot];
    }
}


-(void)handleSingleTapWithinDot:(UITapGestureRecognizer *)recognizer
{
    NSLog(@"in handleSingleTap");

    InfoViewController *view = [[InfoViewController alloc] init];
    view.delegate = self;

    /**I would need to pass DOT object info to InfoViewController.**/

    // Open popup view controller is it isn't already presented by the main controller
    BOOL modalPresent = (BOOL)(self.presentedViewController);
    if (!modalPresent)
    {
        view.modalPresentationStyle = UIModalPresentationFormSheet;
        view.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentViewController:view animated:YES completion:nil];
    }
}
-(void)handleSingleTapWithinDot:(UITapGestureRecognizer *)recognizer
{
    // This assumes that this tap handler is only used for DOTAbstractDotView objects.
    // Otherwise you need to do a type check.
    DOTAbstractDotView *dotView = (DOTAbstractDotView *)recognizer.view;
    // ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM