-2

How Can i Call

-(void)drawRect:(CGRect)rect

in https://github.com/stkim1/MTImageMapView/blob/master/MTImageMapView/MTImageMapView.m

From Another UiViewController Periodically With NSTimer

rva
  • 57
  • 1
  • 9
  • 2
    Why you need to call drawrect() as its default method and will call automatically while initialize. Please specify why you need to call drawract() periodically ? – CodeChanger Feb 01 '17 at 09:12
  • 1
    Do you have an instance of this map view in a UIView on your UIViewController? Just call `setNeedsDisplay` on that view, and it will take care of the redraw. You shouldn't access drawRect directly - it will be called by the controlling class as required – Russell Feb 01 '17 at 09:12
  • CodeChanger- Actually I wanted To Show a Location Marker in state, and i need To Update marker in to Another State with every second, i have made a logic to show a location marker and to which state it should go next but, can't update the view – rva Feb 01 '17 at 10:16
  • create one method and in that method you can change value of your marker and call `setNeedtoDisplay()` to redraw that view. – CodeChanger Feb 01 '17 at 10:20
  • CodeChanger - i have tried that but `setNeedtoDisplay()` isn't responding – rva Feb 01 '17 at 10:22

2 Answers2

3

From the documentation:

Discussion

The default implementation of this method does nothing. Subclasses that use technologies such as Core Graphics and UIKit to draw their view’s content should override this method and implement their drawing code there. You do not need to override this method if your view sets its content in other ways. For example, you do not need to override this method if your view just displays a background color or if your view sets its content directly using the underlying layer object.

...

If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation.

This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. You should never call this method directly yourself. To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay or setNeedsDisplayInRect: method instead.

vadian
  • 274,689
  • 30
  • 353
  • 361
0

YES i Found The solution i am calling a function with timer at the End of a drawrect function and calling setNeedsDisplay()in it

rva
  • 57
  • 1
  • 9