1
    - (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.
}

The error is: Use of underclared identifier 'window'

Stewbob
  • 16,759
  • 9
  • 63
  • 107
  • 2
    There is no reason to create new reference like `UITouch *touchX`, you can use first one every time. – beryllium Apr 09 '12 at 14:49
  • 2
    There's an elegant solution here: http://stackoverflow.com/questions/4982277/uiview-drag-image-and-text/8332581#8332581 It involves subclassing but that shouldn't be a problem. – Rok Jarc Apr 09 '12 at 17:06

1 Answers1

1

You could set the tag property of UIImageView of each one of the letters and check against them on 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;
    }
}

Edit

Using @beryllium 's comment:

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

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

Also note that you should get the images' superview location, and not from the image itself.

Lucien
  • 8,263
  • 4
  • 30
  • 30
  • @beryllium comment makes sense, my answer is valid if you want to treat the touched views differently. – Lucien Apr 09 '12 at 14:53