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 3848636
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:43:52+00:00 2026-05-19T16:43:52+00:00

I want to define a class of draggable images subclassing UIImageView, separating how they

  • 0

I want to define a class of draggable images subclassing UIImageView, separating how they look (on the subclass) and what the user interface react to where they move (on the viewcontroller)

myType1Image.h

@interface myType1Image : UIImageView { } 

myType1Image.m

...
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { 
// Retrieve the initial touch point 
} 
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { 
// Move relative to the original touch point with some special effect
} 
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { 
// Notify the ViewController ... here is my problem...how?
// would call GotIt on viewController for example
}
...

viewcontroller implementation

....
  myType1Image *img = [[myType1Image alloc] initWithImage:[UIImage imageNamed:@"iOSDevTips.png"]];
  img.center = CGPointMake(110, 75);
  img.userInteractionEnabled = YES;
  [subview addSubview:img];
...

- (void) gotIt:(id) (myType1Image *)sender{
    if (CGRectContainsPoint( myimage.frame, [sender.center] )){
        NSLog(@"Got IT!!!");
    }
}

....

I can’t figure out how ViewController could be notified from the myType1Image class, for touchesEnded (for example).
I did it writing all code on the viewcontroller, but I want to do it using subclasses so I can separate the event handling and the visualization of the images from the real funcionality of my interface.
So if I have 15 draggable images, I haven’t to guess what image is touching, and deciding the visual effects to apply.

Is it possible? Is an erroneus aproach?

  • 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-19T16:43:52+00:00Added an answer on May 19, 2026 at 4:43 pm

    First, class names should always begin with a capital letter (MyType1Image).

    Create a MyType1ImageDelegate protocol in which you declare delegate methods that the image view sends to its delegate (the view controller). The first argument of these methods should always be of the type MyType1Image * (to tell the delegate from which object the message comes).

    Your MyType1Image also needs a id <MyType1ImageDelegate> delegate property.

    When your view controller creates an image view, it sets itself as the image view’s delegate. Whenever the image view wants to send a message to the view controller, you have it send the message to the delegate.

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

Sidebar

Related Questions

I have a user define class inside my zend application(as default) application/library/Custom_/Custom_Test.php I want
I want to define a class that supports __getitem__ , but does not allow
I want to define a class method that has access to a local variable.
I want to define a JavaScript class, Foo. Foo = function(value){ this.value = value;
I want to define some properties on a class using the [Indexable()] attribute in
I want to define a generic class in c++ that allow to execute my
I want to define a base class that defines a main method that instantiates
I want to define a class like this class HttpRestAccessor { public: IResource& UpdateResource(string&
I want to define a class whose instances can be constructed, implicitly constructed, or
Here's the scenario: I want define a base class that allocate some buffer once

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.