Search code examples
iphoneiosobjective-cuiviewuiviewcontroller

How to call UIView method from another ViewController in iOS


I have implemented freehand sketch tutorial from

http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_freehand-drawing/. 

I need to call its - (void)drawBitmap; - (void)drawBitmapGreen; methods in my View controller for color change on button action. I have done something like below.

#import <UIKit/UIKit.h>
#import "checklistController.h"
@interface SmoothedBIView : UIView

@property(nonatomic,assign) checklistController *trnsferColor;
- (void)drawBitmapGreen;
@end

@implementation SmoothedBIView

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self drawBitmapred];
    [self drawBitmapGreen];
    [self setNeedsDisplay];
    [path removeAllPoints];
    ctr = 0;
}
- (void)drawBitmapGreen
{
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);
    if (!incrementalImage) // first time; paint background white
    {
        UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds];
        [[UIColor clearColor] setFill];
        [rectpath fill];
    }
    [incrementalImage drawAtPoint:CGPointZero];
    [[UIColor greenColor] setStroke];
    [path stroke];
    incrementalImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //SmoothedBIView.trnsferColor = self;
}

...

 @interface checklistController :   UIViewController

 @property(nonatomic,strong) IBOutlet UIView *vPaintPreview; //SmoothedBIview outlet for hidden and unhidden property.
 @property(nonatomic,assign) SmoothedBIview *SBIView;
-(IBAction)editvImage;
-(IBAction)RedSketch;
-(IBAction)GreenSketch;

Updated code

@implementation file

-(IBAction)GreenSketch
{
    SmoothedBIView *SBIview = [[SmoothedBIView alloc] init];
    [SBIview drawBitmapGreen];
}

What am I doing wrong here?


Solution

  • Have you tried the following:

    -(IBAction)GreenSketch
    {
        SmoothedBIView *SBview = [[SmoothedBIView alloc] init];
        [SBview drawBitmapGreen];
        [SBview setNeedsDisplay];
    }