0

我有课程 *ColorViewController *DrawRectangle

在 ColorViewController.h 中:

#import "DrawRectangle.h"
@interface ColorViewController : UIViewController {
DrawRectangle *DrawRectangle;
}

@property (nonatomic,retain) DrawRectangle *DrawRectangle;

在 DrawRectangle.h 中:

@interface DrawRectangle : UIView {
CGFloat redc;
}
@property (nonatomic) CGFloat redc;

我还将 ViewController.xib 中的 DrawRectangle 类添加到 UIView 之一。

我想从文件 ColorViewController.m 更改 CGFloat redc 的值我这样做是这样的:

- (void)viewDidLoad
{
CGFloat myfloat = 1.0;
self.DrawRectangle.redc = myfloat;

我在 DrawRectangle 中用这个“redc”调用 NSLog,但它每次都说 0.0000000。

如何从 ViewController 替换“redc”的值?我认为我不需要使用 NSNotification,如果我将 DrawRectangle 加载到 ViewController 中,一定有更简单的方法。

4

1 回答 1

2

看起来您的对象尚未实例化。尝试:

-(void)viewDidLoad {
    [super viewDidLoad];

    CGFloat myfloat = 1.0;
    [drawRectangle setRedc:myfloat];
}

作为一般编程实践,您还应该避免将对象命名为与类相同的名称。我建议将对象重命名为drawRectangle.

您还需要在您的 xib 中连接您的 drawRectangle 对象

@property (nonatomic, retain) IBOutlet DrawRectangle *drawRectangle;
于 2012-04-05T23:06:04.043 回答