ios - Overriding drawRect method in a UIView subclass & call it into another UIViewcontroller -


i novice ios programmer , first project.i going develop project ipad. in project need draw several circles & display data on parsing xml element.i have done the circle drawing part subclassing uiview class , overriding drawrect method. load uiview subclass in uiviewcontroller via loadview method .now need

  • touch circle , switch uiviewcontroller.

i not sure how switch uiviewcontroller because of drawing , touch detecting code in uiview subclass.

a appreciated

you need use delegate method tell parent view controller there touch, can present view controller.

at top of uiview subclass header, add this:

@protocol mycustomviewdelegate <nsobject>  - (void)customviewcircletapped;  @end 

then, in declaration of view (the existing declaration have of custom view subclass):

@interface mycustomview : uiview  ...  @property (weak) id<mycustomviewdelegate> delegate; 

after that, in view controller, need set view.delegate = self, view can reference view controller.

then, in view controller header, change declaration this:

@interface myviewcontroller : uiviewcontroller <mycustomviewdelegate> 

then implement customviewcircletapped in view controller implementation:

- (void)customviewcircletapped {     ... // open view controller or } 

once have done that, in touch detection code in view, can add:

[self.delegate customviewcircletapped]; 

what gives custom view ability tell parent view controller has happened, calling method (you can change , add arguments if need pass data), , view controller can open view controller or perform action based on this.

view detects touches → process touches → call customviewcircletapped delegate method on view controller → view controller opens view controller


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -