我是目标C的新人。在这里,我想问一个简单的问题
我在storyboard
中创建了一个视图控制器,并使用UIView
的子类自定义了它的视图
但是,我不知道如何在视图控制器中调用视图的方法。有人可以帮忙吗?我想要做的就是从drawLine:pointStore
ChartViewController.m
中的chartView.m
以下是我的一些代码 ChartViewController.h
#import <UIKit/UIKit.h>
@class chartView;
@interface ChartViewController : UIViewController{
chartView *chart_view;
}
ChartViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableDictionary *pointStore = [[NSMutableDictionary alloc]init];
NSNumber *initX;
NSNumber *initY;
NSMutableDictionary *variableSet = [[NSMutableDictionary alloc]init];
for(initX = [NSNumber numberWithDouble:-10.0f];initX.floatValue<=10.0f;initX = [NSNumber numberWithDouble:(initX.floatValue+0.5f)] )
{
[variableSet setValue:initX forKey:@"x"];
initY = [NSNumber numberWithDouble:[self.brain performOperation:equationOfChart withVariable:variableSet]];
[pointStore setObject:initX forKey:initY];
}
[chart_view drawLine:pointStore];
}
chartView.h
@interface chartView : UIView
@property (nonatomic, strong) NSString *equation;
-(void) getEquation:(NSString *)Equation;
-(void) drawLine:(NSMutableDictionary *)pointsStore;
@end
chartView.m
-(void)drawLine:(NSMutableDictionary *)pointsStore{
CGContextRef c = UIGraphicsGetCurrentContext();
CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
CGContextSetStrokeColor(c, red);
CGContextBeginPath(c);
CGContextStrokePath(c);
for(NSNumber *ax = [NSNumber numberWithDouble:-10.0f];ax.floatValue<10.0f;){
float ay = [[pointsStore objectForKey:ax]doubleValue];
ax = [NSNumber numberWithDouble:(ax.floatValue+0.5f)];
int by = [[pointsStore objectForKey:ax]doubleValue];
[self.class line:ax.floatValue y:ay x2:(ax.floatValue+0.5) y2:by];
}
}
答案 0 :(得分:0)
您应该检查是否已创建并分配了chart_view
的实例。可能你在那个poiner中没有。
如何执行此操作 - 取决于您选择创建视图的方式:在Interface Builder中或动态地,在代码中。
答案 1 :(得分:0)
ChartViewController.h
#import <UIKit/UIKit.h>
@class chartView;
@interface ChartViewController : UIViewController
@property (string, nonatomic) chartView *chart_view;
@end
chartView.m
- (void)viewDidLoad
{
[super viewDidLoad];
...
// Don't forget to alloc and init
self.chart_view = [[chartView alloc] init];
[self.chart_view drawLine:pointStore];
}