Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4622808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:53:45+00:00 2026-05-22T02:53:45+00:00

I’m going to be using the same code that I have in my view

  • 0

I’m going to be using the same code that I have in my view controller in several views and I don’t want to have to paste the code into each.

Can someone show me a few lines of code showing me how to do this ?

I’m guessing i’m going to have to declare an instance of the class in the interface and put a hand back method for each of touch functions I’ll be sub classing ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:53:45+00:00Added an answer on May 22, 2026 at 2:53 am

    If I understand the question correctly you want the same bit of code executed for touchesBegan, touchesMoved… from each of your views.

    The way I would do this would be using the delegate pattern.

    @protocol ViewTouchDelegate
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    @end
    
    @interface ViewA : UIView {
        id <ViewTouchDelegate> touchDelegate;
    }
    
    @implementation ViewA
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        [self->touchDelegate touchesBegan:touches withEvent:event];
    }
    @end // End View A
    
    @interface ViewB : UIView {
        id <ViewTouchDelegate> touchDelegate;
    }
    
    @implementation ViewB
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        [self->touchDelegate touchesBegan:touches withEvent:event];
    }
    @end // End View B
    

    This will let you put all your touch handling code in one place (in a class that conforms to the ViewTouchDelegate protocol), and give that delegate to each of your views.

    In my example I have made the signature of touchesBegan the same as UIResponder’s touchesBegan, but you can tailor it to your needs.

    Edit: Example ViewTouchDelegate

    @interface MyViewTouchDelegate : NSObject <ViewTouchDelegate>
    @end
    
    @implementation MyViewTouchDelegate
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        //put all your common touch handling code in here
    }
    @end
    

    Define any additional methods you need in the ViewTouchDelegate protocol for your purposes, for example touchesMoved, touchesEnded, yourOwnCustomEvent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.