On Dec 8, 2009, at 12:33 pm, mmalc Crawford wrote:
Get the logic right...

> - (void)setUpTouchHandling {
> 
>    touchToLabelMapping = CFDictionaryCreateMutable (kCFAllocatorDefault, 5, 
> &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
>    availableLabels = [[NSMutableArray alloc] initWithObjects:touchLabel1, 
> touchLabel2, touchLabel3, touchLabel4, touchLabel5, nil];
> }
> 
- (void)setUpTouchHandling {
    
    touchToLabelMapping = CFDictionaryCreateMutable (kCFAllocatorDefault, 5, 
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    availableLabels = [[NSMutableArray alloc] initWithObjects:touchLabel1, 
touchLabel2, touchLabel3, touchLabel4, touchLabel5, nil];
    setUp = YES;
}


... and improve the user experience accordingly:

> - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
> 
>    for (UITouch *touch in touches) {
>        if (touch.view == self) {
>            UILabel *label = (UILabel 
> *)CFDictionaryGetValue(touchToLabelMapping, touch);
>            label.text = @"{0, 0}";
>            CFDictionaryRemoveValue (touchToLabelMapping, touch);
>            [availableLabels addObject:label];
>        }
>    }
> }    
> 
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    for (UITouch *touch in touches) {
        if (touch.view == self) {
            
            UILabel *label = (UILabel 
*)CFDictionaryGetValue(touchToLabelMapping, touch);
            label.text = @"{0, 0}";
            CFDictionaryRemoveValue (touchToLabelMapping, touch);
            [availableLabels insertObject:label atIndex:0];
        }
    }
}


(I'm using setUpTouchHandling so that this will work however you configure your 
view or view controller -- ideally you choose a more appropriate initialisation 
locus.)

mmalc


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to