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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:52:56+00:00 2026-06-05T22:52:56+00:00

Background: I have an MVC based polaroid object. The model keeps the photo’s metadata,

  • 0

Background:

I have an MVC based polaroid object. The model keeps the photo’s metadata, and image. The view displays the photo’s name and image (via UIView). The controller has access to the model and the view and coordinates the operations between them (eg. fade-in model photo on view)

My objective:

I want to implement a simple drag-and-drop function in my program so the user can drag a polarid’s view and viewcontroller into an album.

The problem:

I’m able to add the UIPanGestureRecognizer to my polaroid’s view. However, I’m unable to access the viewcontroller or model from the polaroidPanned method.

Adding the UIPanGestureRecognizer:

 UIPanGestureRecognizer *panRecogniser = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(polaroidPanned:)];
    [polaroidController.polaroidView addGestureRecognizer:panRecogniser];

Here’s the UIPanGestureRecognizer handler:

    - (void) polaroidPanned: (UIPanGestureRecognizer *) panGesture
{
    CGPoint touchLocation = [panGesture locationInView:self.view];

    //While being dragged
    if ([panGesture state] == UIGestureRecognizerStateBegan || [panGesture state] == UIGestureRecognizerStateChanged) 
    {
        //update the album view to the touch location
        [panGesture view].center = touchLocation;
    }
    else  if ([panGesture state] == UIGestureRecognizerStateEnded && isOntopOfAlbum)
    {
        //HERE I WANT TO PASS THE VIEW CONTROLLER OF THE [panGesture view] to my album
        [album addPolaroidViewController: ????]

    }
}

I’m able to pass the view, but I cannot seem to be able to reference the view’s ViewController.

Does anyone know how I could accomplish this? Or work around it?

  • 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-06-05T22:52:56+00:00Added an answer on June 5, 2026 at 10:52 pm

    Assuming you cannot change the code of your PolaroidViewController or PolaroidView. You have alternatives. One of them is using associating objects.

    In Objective-C you can insert runtime properties in objects. It’s comes with a couple of “gotcha” but if you have no control over the view and the controller this might help.

    First import objc/runtime.h in your source

    #import <objc/runtime.h>
    

    Declare a key used for getting your associate object

    const NSString* kViewController = @"panGestureViewController";    
    

    Then when you create your UIPanGestureRecognizer you associate an object like so:

    // Create
    UIPanGestureRecognizer *panRecogniser = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(polaroidPanned:)];
    [polaroidController.polaroidView addGestureRecognizer:panRecogniser];
    // Associate
    objc_setAssociatedObject(panRecogniser, &kViewController, polaroidController,OBJC_ASSOCIATION_ASSIGN);
    

    To retrieve the associate object in your handler

    - (void) polaroidPanned:(UIPanGestureRecognizer *)panGesture
    {
        PolaroidViewController* viewController = ((NSNumber*)objc_getAssociatedObject(panGesture, &kViewController)
        //...    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have MVC 3 application. In one of div's I set background-image. #wrapper {
Background: I have an MVC layout (master) view which uses @Html.RenderAction to display a
background:Me and my coworkers are working on asp.net mvc project ... we have a
Background I have a function that takes a config object as an argument. Within
Background I have an existing extension designed to accompany a browser-based game (The extension
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
I have a mvc view made up of a matrix of radio buttons. Each
Background: I am working on an ASP.NET MVC app that has 3 partials (based
Technical Details C#, ASP.NET 4, MVC 3, SQL backend, ADO.NET (edmx) Background/Context I have
Background: I have a website (ASP.NET MVC) where users can write/edit/delete a review. Doing

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.