无法获取 UIView 的确切标签值
我正在尝试使用以下代码将视图标签与另一个标签进行比较,
for(UIView *subView in cardsContainerView.subviews){
NSNumber *viewTag = [NSNumber numberWithInt:subView.tag];
NSLog(@"The subView tag is %d",viewTag);
if([[dataDict valueForKey:@"savedPositions"]containsObject:viewTag]){
[tempArray addObject:viewTag];
[self rearrangeView:subView and:subView];
}
但在看到 Log 语句后,我发现我的标签值与我之前给出的值相差甚远。我得到的标签是这个
89212864。
谁能帮我知道这种行为的原因吗?
I am trying to compare a view tag with another tag by using the following code
for(UIView *subView in cardsContainerView.subviews){
NSNumber *viewTag = [NSNumber numberWithInt:subView.tag];
NSLog(@"The subView tag is %d",viewTag);
if([[dataDict valueForKey:@"savedPositions"]containsObject:viewTag]){
[tempArray addObject:viewTag];
[self rearrangeView:subView and:subView];
}
But after seeing the Log statements i found out that my tag value is no where close to what i have given it previously. Theh tag that i got is this
89212864.
can anyone help me know the reason for this behavior please??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
Try this
viewTag 是一个对象,如果您只是将其传递给 NSLog,它会打印实例的 id(在整数的上下文中),这就是给您带来奇怪结果的原因。您必须向 viewTag 询问其整数值:
viewTag is an object, if you just pass that to the NSLog it will print you the id of the instance (in the context of an integer), which is what gives you the weird result. You have to ask viewTag for its integer Value: