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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:20:19+00:00 2026-06-01T01:20:19+00:00

I have an imageview to which I have added certain custom subview as dots.

  • 0

I have an imageview to which I have added certain custom subview as dots.
There is also an NSMutableArray where I add the corresponding CGPoint.
I also add set the same CGPoint as property in the custom dot subview.

When I try to delete a random point out of the total in the Array,
I delete it both from array and remove the corresponding subview from ImageView if its datapoint property matches with the same one which was in the array on that index.

This is my code in the touchesStarted of the custom ImageView to add the datapoint.
There is also some extra code to keep the latest added point of yellow color and old ones to be red.

    SBPointView *pointView = [[SBPointView alloc] initWithFrame:CGRectMake(touchPoint.x - kPointViewSize/2, touchPoint.y - kPointViewSize, 5, 5)];
    pointView.backgroundColor = [UIColor yellowColor];
    pointView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

    CGSize imageSize = self.image.size;
    CGRect frame = self.frame;
    CGAffineTransform transform = self.transform;
    CGAffineTransform scaleTransform = CGAffineTransformMakeScale(imageSize.width/frame.size.width, imageSize.height/frame.size.height);
    transform = CGAffineTransformConcat(transform, scaleTransform);

    CGPoint dataPoint = CGPointApplyAffineTransform(touchPoint, transform);//[mOfflineView convertPoint:touchPoint fromView:self];//[self convertPoint:touchPoint toView:mOfflineView];
    NSLog(@"**** Datapoint = %@", NSStringFromCGPoint(dataPoint));
    pointView.dataPoint = dataPoint;
    [mDataPoints addObject:NSStringFromCGPoint(dataPoint)];
    for (SBPointView *tempPointView in self.subviews) {
        if ([tempPointView isKindOfClass:[SBPointView class]]) {
            tempPointView.backgroundColor = [UIColor redColor];
        }
    }
    [self addSubview:pointView];
    [pointView release];

And Here is my code to delete a random PointView,

    -(void)deleteDatapointAtIndex:(NSUInteger)index{
        if (index < [mDataPoints count]) {
        CGPoint dataPoint = CGPointFromString([mDataPoints objectAtIndex:index]);
        for (SBPointView *subview in self.subviews) {
            if ([subview isKindOfClass:[SBPointView class]]) {

            if (subview.dataPoint.x == dataPoint.x && subview.dataPoint.y == dataPoint.y) {
                [mDataPoints removeObjectAtIndex:index];
                [subview removeFromSuperview];
                break;
            }
        }

    }

 }
}

But for some reason I don’t know why, I can’t delete certain datapoints from the array and also the remove the subviews and the if condition fails, am I doing something wrong here, which I cant see.

UPDATE : I have tried to put an NSLog in the for loop to check what all datapoints i am checking against and what datapoint I have selected from the index,
turns out the that in the cases where If fails
I have a point like this,
{483.2, 601.6} and these are the points left {483.2, 601.6}, {483.2, 681.6}.

Its quite clear that my CGPoint is same as the first one {483.2, 601.6}

and in the if condition I am checking for equality f both x and y of both CGPoints but the if condition is still failing !
is it something to do with precision loss when converting CGPoint to string and back ?

  • 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-01T01:20:21+00:00Added an answer on June 1, 2026 at 1:20 am

    This looks like it’s a case of the float comparison problem. Quite simply, just because two floating point numbers should be equal doesn’t mean they actually are.

    float f1 = 21.9876;
    float f2 = 22.2345;
    

    Your calculator will tell you that (f2 – f1) = 0.2469, but this is not guaranteed in a C-based language. Put the following in a file called test.m

    #import <CoreFoundation/CoreFoundation.h>
    int main() {
            float f1 = 21.9876;
            float f2 = 22.2345;
            while (f2 - f1 != 0.2469)
                    NSLog(@"HA");
            return 0;
    }
    

    And then use Terminal to compile it with GCC

    $ gcc -framework Foundation test.m -o test; ./test
    

    Your computer will be laughing at you for trying to compare two floats with “==”. A more appropriate way to compare two floats is to do something like this:

    float f1 = 21.9876;
    float f2 = 22.2345;
    if (fabs(f2 - f1) < 0.00001) // If the difference between them is this small, they are effectively equal
    

    Of course the more technically correct version of that would use FLT_EPSILON instead of 0.00001. This question is similar.

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

Sidebar

Related Questions

I have an imageView, to which, I have added UIPinchGestureRecognizer and UIRotationGestureRecognizer. in pinch
I already have a custom UIAlertView and in which i want to add UIImageView
I have an imageview in which I want an image to be set. My
I have an ImageView which is add to UIView. Now i need to zoomIn
I have one uiimageview which is added as subview in uiview. frame for uiimageview
I have added an imageView of size 300*300 into the interface in my ipad
I have created one gridview and use custom adapter for that. I added two
I have an ImageView from which I want to copy a piece of it
I am creating an app, in which I have two small imageview (using have
I am trying to add animation for UIImages which are added in an array.

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.