Xcode:标签制作错误

时间:2012-04-09 14:37:11

标签: ios xcode xcode4 window

    - (void)viewDidLoad
{
    CGRect frame = CGRectMake(20, 45, 140, 21);
    UILabel *label = [[UILabel alloc] initWithFrame:frame];

    [window addSubview:label];
    [label setText:@"Hello world"];
    [label release];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

错误是:使用未声明的标识符'window'

2 个答案:

答案 0 :(得分:1)

您可以为每个字母设置UIImageView标记属性,并在touchesMoved上对其进行检查。

- (void)touchesMoved:(NSSet*)touches withEvent: (UIEvent*)event{

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view.superview];

    switch (touch.view.tag) {
        case 0:
            a.center=location;
            break;
        case 1:
            b.center=location;
            break;
        case 3:
            c.center=location;
            break;
    }
}

修改

使用@beryllium的评论:

- (void)touchesMoved:(NSSet*)touches withEvent: (UIEvent*)event{

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view.superview];
    touch.view.center = location;
}

另请注意,您应该获取图像的超级视图位置,而不是图像本身。

答案 1 :(得分:1)

我的回答比你想做的要多一些,但它应该可以帮到你很多:https://stackoverflow.com/a/9689832/542400