Search code examples
iosuiviewmkmapviewpushviewcontrolleruser-interaction

iOS UIView push view controller


Is it possible to push a view controller when a user selects a UIView? I have a UIView that displays an address and coordinates in it and when the user touches it, I want it to push to my map view controller where it will plot the annotation and so on... Thanks!


Solution

  • Your address and coordinates should be inside a view (like a Label). If you setup a tap guesture on it, then the on tap, you can push the view controller.

    For example, if it's a label, here's a relevant SO post showing handling a tap on a label: iOS using UITapGestureRecognizer with UILabel to swipe to the next page

    In that example, they are scrolling to the next page, in your code, you would push the view controller.

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleAddressTap:)]; 
    [view.addressLabel addGestureRecognizer:tap];  // bind the tap to your label with your address ...
    
    - (void) handleAddressTap: (UIGestureRecognizer *) gesture {
        // push your view controller here
    }