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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:59:47+00:00 2026-05-15T10:59:47+00:00

I have a UIViewController whose view has a custom subview. This custom subview needs

  • 0

I have a UIViewController whose view has a custom subview.

This custom subview needs to track touch events and report swipe gestures.

Currently I put touchesBegan, touchesMoved, touchesEnded and touchesCancelled in the subview class. With some extra logic I am able to get swipe gestures and call my handleRightSwipe and handleLeftSwipe methods. So now when I swipe within the subview it calls its local swipe handling methods. This all works fine.

But what I really need is for the handleRightSwipe and handleLeftSwipe methods to be in the view controller. I could leave them in the subview class but then I’d have to bring in all the logic and data as well and that kind of breaks the MVC idea.

So my question is is there a clean way to handle this? Essentially I want to keep my touch event methods in the subview so that they only trigger for that specific view. But I also want the view controller to be informed when these touch events (or in this case swipe gestures) occur.

Any ideas?

Thanks.

UPDATE:

Using Henrik’s suggestion, here’s a quick sample of what I did (to save you the reading):

I set my view controller as an observer of notifications (early on).

// NOTIFICATION_LEFT_SWIPE is defined as some unique string elsewhere.
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

// Note that imageView is the instance of my subview that is calling the notification.
// You can set this to nil if you don't want it to be specific.
[nc addObserver:self selector:@selector(handleLeftSwipe) name:@NOTIFICATION_LEFT_SWIPE object:imageView];

Then I implement the handleLeftSwipe method. This will be called when a notification is received.

Now in my subview I send a notification when a swipe gesture is received:

// Note that NOTIFICATION_LEFT_SWIPE is the same one used in the view controller
// I put this in a global header I use.  This is how you keep track of notifications.
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@NOTIFICATION_LEFT_SWIPE object:self]; 

And similarly for the right swipe.

  • 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-15T10:59:48+00:00Added an answer on May 15, 2026 at 10:59 am

    You could use the Notification Center to send notifications to different (observing) objects.

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

Sidebar

Ask A Question

Stats

  • Questions 440k
  • Answers 440k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you really need to then jQuery has methods for… May 15, 2026 at 5:16 pm
  • Editorial Team
    Editorial Team added an answer Depending on the nature of your .txt documents, you don't… May 15, 2026 at 5:16 pm
  • Editorial Team
    Editorial Team added an answer Near future? I wouldn't count on it. As http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport lays… May 15, 2026 at 5:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.