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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:57:37+00:00 2026-05-26T21:57:37+00:00

I believe I may be dealing with some view issues which are not allowing

  • 0

I believe I may be dealing with some view issues which are not allowing me to detect and add UIImageView objects to an array. I could really use some suggestions.

I’ve got a number of UIImageViews with images linked to a UIView that sits on top of a UIViewController (the UIView was added to help with drawRect and some additional advantages). So, when I touch an image and ‘drag and drop’ it, I want to add that image to an array upon being dropped.

My touchesBegan gets the location of the touch and checks UIImageView is being touched and then centers on that view as follows:

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

            UITouch *touch = [[event allTouches] anyObject];

            CGPoint location = [touch locationInView:self];  //can't use self.view in a UIView, this may be causing issues?

            startLocation = location;  // for reference as needed



    NSLog(@"Image x coord:   %f", location.x);

    NSLog(@"Image y coord:   %f", location.y);

    if ([touch view] == obiWan_Block)

            {obiWan_Block.center = location;}

    else if ([touch view] == r2d2_Block)

            {r2d2_Block.center = location;}

    else if ([touch view] == you_Block)

            {you_Block.center = location;}

}

Then, I drag the UIImageView around with touchesMoved and finally, ‘drop’ the image with touchesEnded. When the UIImageView is drop in a certain area of the screen, I ‘snap’ it to a specific location. It’s at this point I want to place this UIImageView into an array, but I’m having no luck. I believe I’m getting confused on the various views being touched and what’s getting added via addObject to my NSMutableArray. Or, I could be missing something completely. Here’s my touchedEnded method:

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

          UITouch *touch = [[event allTouches] anyObject];

          CGPoint location = [touch locationInView:self];

          UIView *temp = [touch view];

          UIImageView *currentImageView = (UIImageView *)[touch view];  //DON'T THINK THIS IS RIGHT

    NSLog(@"Current Image View is:   %@", currentImageView);

    if ((location.x > dropZone.origin.x) && (location.y >= dropZone.origin.y) && ([touch view] != NULL))

        {

            CGRect frame = temp.frame;

            if (touchCount == 0) {

                frame.origin.x = 15;

                frame.origin.y = 180;

                temp.frame = frame;

                [quoteArray addObject: currentImageView];

                touchCount++;

                }

            else if (touchCount == 1) {

                frame.origin.x = 70;

                frame.origin.y = 180;

                temp.frame = frame;

                [quoteArray addObject: currentImageView]; 

                touchCount++;

                }

                ....

I have an NSLog statement to check if addObject is working as follows:

NSLog(@"the quote array contains %d items. Contents = %@",[quoteArray count], quoteArray);

The log always says:

the quote array contains 0 items. Contents = (null)

Please advise and thanks!

  • 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-26T21:57:37+00:00Added an answer on May 26, 2026 at 9:57 pm

    Your last part of code shows that you have uninitialized quoteArray. Check code when you create it, I guess you missed something in your init method. Because if array was correct then NSLog should show below:

    NSArray *quoteArray = [NSArray array];
    NSLog(@"%@", quoteArray); 
    

    2011-11-17 17:37:00.506 TestApp[1382:207] ( )

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

Sidebar

Related Questions

I'm having a real trouble to get accents right, and I believe this may
I believe this code may require more effort to comprehend than average, so I'm
I believe the application has some parts that target .NET, and some that don't.
I believe any programmer who has been dealing with database requests in a gui
I believe several of us have already worked on a project where not only
I believe this may be a simple question, but I've looked everywhere and tried
I have some PNG's being moved around a screen in a repeated loop which
I believe there may be a bug in chrome's rendering of border colors. Here
We have some software which relied on certain behavior from another ( very commonly
EDIT: I believe i may have found the problem. I need to work on

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.