Nested functions not allowed in drawrect problem
Posted
by
Martin
on Stack Overflow
See other posts from Stack Overflow
or by Martin
Published on 2011-02-16T22:29:59Z
Indexed on
2011/02/17
7:25 UTC
Read the original article
Hit count: 223
objective-c
|cocoa
I have a custom view onto which I draw some graphics from the drawrect function, which works fine.
However I like to draw based on the contens of an array I pass on the the view just before I do a setNeedsDisplay. In the drawRect function I try to access the array but then I get a nested functions error which I do not understand.
Here's my code:
//
// MyView.h
// window
//
#import <UIKit/UIKit.h>
@interface MyView : UIView {
NSArray * nary;
}
@property (nonatomic, copy) NSArray *nary;
@end
//
// MyView.m
// window
//
#import "MyView.h"
@implementation MyView
@synthesize nary;
CGContextRef c;
CGFloat black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
c = UIGraphicsGetCurrentContext();
CGContextSetStrokeColor(c, black);
NSLog(@"mview");
NSArray *ns = [nary objectAtIndex:0];
}
- (void)dealloc {
[super dealloc];
}
@end
© Stack Overflow or respective owner