我有一个自定义的视图,我从drawrect函数中绘制了一些图形,这很好地工作。正确的问题不允许嵌套的函数
但是我喜欢根据数组的维数来绘制,我在setNeedsDisplay之前传递视图。在drawRect函数中如果我用drawRect使用NSString或NSarray,我得到一个嵌套的函数错误,我不明白?
这里是我的代码:
// MyView.h
#import <UIKit/UIKit.h>
@interface MyView : UIView {
}
@end
// MyView.m
#import "MyView.h"
@implementation MyView
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);
//Gives a nested functions are disabled error at compiletime
NSString nsz * = @"test";
}
- (void)dealloc {
[super dealloc];
}
@end
@Joe你可以,但不建议。如果`nary`是一个包含格式说明符的字符串(如`%@`),那么`NSLog()`将尝试读取堆栈中不是实际对象的数据,您可能会崩溃。但它仍然*可能*。 – 2011-02-16 22:36:07
NSLog只是为了检查它我可以看到数组中的数据(我可以),所以它不会在代码中,但没有来自NSLog – Martin 2011-02-16 22:41:06
的错误我正在使用另一台PC作为邮件。但不是现在/ Users/martinstave/Documents/windowIpadOne /../../下载/ iPhoneLine/MyView.m:134:0 /Users/martinstave/Documents/windowIpadOne/../../Downloads/iPhoneLine/MyView。 m:134:错误:嵌套函数被禁用,使用-fnested函数重新启用 – Martin 2011-02-16 22:55:54