I have a subclass of UIScrollView, it is also the delegate.
When I have the next protocol function called:
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
id element;
NSEnumerator *setEnum = [touches objectEnumerator];
while ((element = [setEnum nextObject]) != nil)
{
NSLog(@"element:%@", element);
}
return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}
The only thing that NSLog is showing is:
element:<UITouch: 0x15a9a0> phase: Ended tap count: 3 window: <UIWindow: 0x392390; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x382cd0>> view: <UIButton: 0x3a5e90; frame = (0 0; 106 138); opaque = NO; layer = <CALayer: 0x3a3e90>> location in window: {228, 126} previous location in window: {227, 126} location in view: {89.6667, 77} previous location in view: {88.3333, 77}
The problem is, it shows the content of the NSSet as one big NSString. If I ask allObjects from the objectEnumerator, I just get one object in an NSArray. Exactly the same object (the NSString) as NSLog is showing.
Could someone please tell me if I am doing something wrong, or if it is not normal that the NSSet is just giving one NSString.
Thank you!
The NSLog()
output is the result of the description
method called on the object. NSLog()
output is designed to be human readable for debugging only.
<UITouch: 0x15a9a0>
indicates the the object is a UITouch
at address 0x15a9a0. The rest of the description just displays some interesting values of the UITouch
.
Try:
NSLog(@"tap count:%d", element.count);
etc. and you will se that it is not just a string.
As an aside there is no need for an explicit NSEnumerator
, fast enumeration ca be used: you can simplify the code to:
for (UITouch *element in touches)
{
NSLog(@"element:%@", element);
}