【发布时间】:2014-10-15 02:32:38
【问题描述】:
我多次尝试修改我的代码,但仍然无法将变量从 UIViewController 传递给 UIView,变量总是返回 (null)。
// BPGraphView.h
@interface BPGraphView : UIView
@property (nonatomic, retain) NSString *test;
@end
// BPGraphView.m
#import "BPGraphView.h"
@implementation BPGraphView
@synthesize test;
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
NSLog(@"test %@",test);
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
NSLog(@"draw %@", test); // always return (null)
if ([test isEqual:@"something"]) {
[self drawOutLine];
}
}
@end
// BloodPressureViewController.m
- (void)viewDidLoad
{
BPGraphView * graphview=[[BPGraphView alloc] init];
graphview.test = @"something";
}
【问题讨论】:
标签: ios objective-c iphone xcode xcode6