UIScrollView的touchesShouldBegin: NSSet只是一个NSString

发布于 2025-01-04 02:13:48 字数 1079 浏览 0 评论 0原文

我有一个 UIScrollView 的子类,它也是委托。

当我调用下一个协议函数时:

- (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];
}

NSLog 显示的唯一内容是:

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}

问题是,它将 NSSet 的内容显示为一个大 NSString。如果我从 objectEnumerator 询问 allObjects,我只会得到 NSArray 中的一个对象。与 NSLog 显示的对象(NSString)完全相同。

有人可以告诉我我是否做错了什么,或者 NSSet 只给出一个 NSString 是否不正常。

谢谢你!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他夏了夏天 2025-01-11 02:13:48

NSLog() 输出是在对象上调用 description 方法的结果。 NSLog() 输出被设计为人类可读,仅用于调试。

表示该对象是地址 0x15a9a0 处的 UITouch。描述的其余部分仅显示 UITouch 的一些有趣的值。

尝试:

NSLog(@"tap count:%d", element.count);

等等,你会发现它不仅仅是一个字符串。

另外,不需要显式的 NSEnumerator,可以使用快速枚举:您可以将代码简化为:

for (UITouch *element in touches)
{
    NSLog(@"element:%@", element);    
}

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);    
}
十雾 2025-01-11 02:13:48

NSSet Touchs 是一组 UITouch 实例,而不是 NSString。当您将其发送到 NSLog 时,它会调用 UITouch 实例的“description”方法,该方法返回一个 NSString。

The NSSet touches is a set of UITouch instances, not NSStrings. When you send it to NSLog, it calls the "description" method of the UITouch instance which does return an NSString.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文