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

  • Home
  • SEARCH
  • 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 5845587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:27:22+00:00 2026-05-22T12:27:22+00:00

I have a basic map view in my app which contains a set of

  • 0

I have a basic map view in my app which contains a set of user definable way points. When the view is loaded I draw a path connecting the way points. This works well.

However, when the user drags a way point around the view, I would like it to re-draw the paths and that is my problem. I dont know how to hacant get it to draw anything after the first time. Here’s my code:

- (void)drawRect:(CGRect)rect { ////// works perfectly

    context = UIGraphicsGetCurrentContext();

    CGContextSetRGBStrokeColor(context, 1, 0, 1, .7);
    CGContextSetLineWidth(context, 20.0);
    WaypointViewController *w = [arrayOfWaypoints objectAtIndex:0];
    CGPoint startPoint = w.view.center;

    CGContextMoveToPoint(context, startPoint.x, startPoint.y);

    for (int i = 1; i<[arrayOfWaypoints count]; i++) {
        WaypointViewController *w2 = [arrayOfWaypoints objectAtIndex:i];
        CGPoint nextPoint = w2.view.center;
        CGContextAddLineToPoint(context,nextPoint.x, nextPoint.y);
    }
    CGContextStrokePath(context);
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if (moving) {
        UITouch *touch = [touches anyObject];
        currentWaypoint.view.center = [touch locationInView:self];
        [delegate setUserInteraction:NO];
        [self drawInContext:context];
        [NSThread detachNewThreadSelector:@selector(drawInContext:) toTarget:self withObject:nil];

    }

}

- (void)drawInContext:(CGContextRef)context { ///gets called, but does nothing

    CGContextSetRGBStrokeColor(context, 1, 0, 1, .7);
    CGContextSetLineWidth(context, 20.0);
    WaypointViewController *w = [arrayOfWaypoints objectAtIndex:0];
    CGPoint startPoint = w.view.center;

    CGContextMoveToPoint(context, startPoint.x, startPoint.y);

    for (int i = 1; i<[arrayOfWaypoints count]; i++) {
        WaypointViewController *w2 = [arrayOfWaypoints objectAtIndex:i];
        CGPoint nextPoint = w2.view.center;
        CGContextAddLineToPoint(context,nextPoint.x, nextPoint.y);
    }

    CGContextStrokePath(context);
}
  • 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-22T12:27:23+00:00Added an answer on May 22, 2026 at 12:27 pm

    You can not use the context that is active in drawRect: anywhere else.

    Instead of calling [self drawInContext:context] call [self setNeedsDisplay]

    The context that you are pointing to in your drawRect: might be freed or might still be active you don’t know, but either way there is no way to get the bits you put into that context onto the screen.

    Also, please read the docs on drawing on iOS here

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

Sidebar

Related Questions

I have an image of a basic game map. Think of it as just
I have a basic CRUD form that uses PageMethods to update the user details,
I have a basic model in which i have specified some of the fields
I have a basic ActiveRecord model in which i have two fields that i
I have a basic 3 tier app Presentation/Web (ASP.NET MVC) Application Services (WCF, hosted
Currently, i have basic C++ and PHP skills. But, i want to switch to
I have a basic form with controls that are databound to an object implementing
I have a basic understanding of mock and fake objects, but I'm not sure
I have a basic cs-major understanding of multi-threading but have never had to do
I have a basic C# console application that reads a text file (CSV format)

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.