簡體   English   中英

如何從iOS中的另一個ViewController調用UIView方法

[英]How to call UIView method from another ViewController in iOS

我已經從實現了寫意素描教程

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

我需要稱之為- (void)drawBitmap; - (void)drawBitmapGreen; 我的View控制器中用於更改按鈕操作顏色的方法。 我做了下面的事情。

#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;

更新的代碼

@implementation file

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

我在這里做錯了什么?

您是否嘗試過以下方法:

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

 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM