Вопрос

I have two UIImageView's in my application, both of which when touched, are to call the same viewController. However, I am trying to figure out a way to distinguish the call made by one UIImageView from the other, and I figure that by giving each UIImageView a tag value would be the way to go.

Now that I have done this, I am trying to figure out how to actually pass it when I call the required viewController? Please bear in mind that the viewController I am calling is created from a .xib file, and is being called from an application built in storyboards.

Here is my method that instantiates and calls the viewController from the UIImageView:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    _nextView = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
    [_nextView setDelegate:(id)self];
    [_nextView setSignatureDelegate:self];
    NextNavigationController *navigationController = [[NextNavigationController alloc] initWithRootViewController:_nextView];
    [self presentViewController:navigationController animated:YES completion:nil];
    
}

As I mentioned, when I make the call to display the viewController, I would like somehow to pass the tag value from the calling UIImageView as well. The tag value for each UIImageView I set in IB via the attributes inspector. How can I do this?

Это было полезно?

Решение

The touches set contains instances of UITouch objects. Use the touch.view property to determine the view object in which the touch originally occurred. Once you have that reference, you can get that view's tag value.

But do consider making these UIButton instances as Jamie mentions in the comments.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top