Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIView无法正确加载?_Iphone_Ios_Objective C_Cocos2d Iphone - Fatal编程技术网

Iphone UIView无法正确加载?

Iphone UIView无法正确加载?,iphone,ios,objective-c,cocos2d-iphone,Iphone,Ios,Objective C,Cocos2d Iphone,我将UIView的代码文件设置为脚本中视图的自定义类。但是,当我运行应用程序并加载视图时,什么都没有发生?我没有得到任何NSLog,没有任何东西被吸引到屏幕上?有人知道我做错了什么吗?我是不是对某些事情做了适当的改进 UIView的我的代码: - (id)initWithFrame:(CGRect)frame { NSLog(@"Drawling area loaded"); self = [super initWithFrame:frame]; if (self) {

我将UIView的代码文件设置为脚本中视图的自定义类。但是,当我运行应用程序并加载视图时,什么都没有发生?我没有得到任何NSLog,没有任何东西被吸引到屏幕上?有人知道我做错了什么吗?我是不是对某些事情做了适当的改进

UIView的我的代码:

- (id)initWithFrame:(CGRect)frame
{
    NSLog(@"Drawling area loaded");
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


- (void)drawRect:(CGRect)rect
{

    CGPoint dotOne = CGPointMake(1, 1);
    [squareLocations addObject:[NSValue valueWithCGPoint:dotOne]];

    CGPoint dotTwo = CGPointMake(10, 10);
    [squareLocations addObject:[NSValue valueWithCGPoint:dotTwo]];

    CGPoint dotThree = CGPointMake(100, 100);
    [squareLocations addObject:[NSValue valueWithCGPoint:dotThree]];


    int numby = [squareLocations count];

    for (int i = 0; i < numby; i++)
    {
        NSValue *pointLocation = [squareLocations objectAtIndex:i];
        CGPoint tmpPoint = [pointLocation CGPointValue];

        CGRect tmpRect = CGRectMake(tmpPoint.x, tmpPoint.y, 10, 10);

        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 5.0);
        CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
        CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
        CGColorRef color = CGColorCreate(colorspace, components);
        CGContextSetStrokeColorWithColor(context, color);
        CGContextMoveToPoint(context, tmpPoint.x, tmpPoint.y);
        CGContextAddLineToPoint(context, 300, 400);
        CGContextStrokePath(context);

    }
}


@end
-(id)initWithFrame:(CGRect)frame
{
NSLog(@“加载的牵引区”);
self=[super initWithFrame:frame];
如果(自我){
//初始化代码
}
回归自我;
}
-(void)drawRect:(CGRect)rect
{
CGPoint dotOne=CGPointMake(1,1);
[squareLocations添加对象:[NSValue valueWithCGPoint:dotOne]];
cgpointdotwo=CGPointMake(10,10);
[squareLocations添加对象:[NSValue valueWithCGPoint:dotTwo]];
CGPoint dotThree=CGPointMake(100100);
[squareLocations添加对象:[NSValue valueWithCGPoint:dotThree]];
int numby=[平方位置计数];
for(int i=0;i
我认为您应该使用调试器来确保
drawRect:
方法中的
squareLocations
ivar不是nil。在objective-c中,您可以向nil发送任何消息,而不会出现任何错误,也不会执行任何操作。另外,在
drawRect:
方法中初始化
squareLocations
ivar可以解决此问题。

尝试添加以下代码:

- (void)setup{
    self.contentMode=UIViewContentModeRedraw;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}
- (void)awakeFromNib{
    [self setup];
}