无法获取 UIView 的确切标签值

发布于 2024-11-02 02:21:42 字数 513 浏览 0 评论 0原文

我正在尝试使用以下代码将视图标签与另一个标签进行比较,

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 技术交流群。

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

发布评论

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

评论(2

柠檬色的秋千 2024-11-09 02:21:42
for(UIView *subView in cardsContainerView.subviews){

    NSNumber *viewTag = [NSNumber numberWithInt:subView.tag];
    NSLog(@"The subView tag is %d",[viewTag intValue]);
    if([[dataDict valueForKey:@"savedPositions"]containsObject:viewTag]){
        [tempArray addObject:viewTag];
        [self rearrangeView:subView and:subView];
    }

试试这个

for(UIView *subView in cardsContainerView.subviews){

    NSNumber *viewTag = [NSNumber numberWithInt:subView.tag];
    NSLog(@"The subView tag is %d",[viewTag intValue]);
    if([[dataDict valueForKey:@"savedPositions"]containsObject:viewTag]){
        [tempArray addObject:viewTag];
        [self rearrangeView:subView and:subView];
    }

Try this

终难遇 2024-11-09 02:21:42

viewTag 是一个对象,如果您只是将其传递给 NSLog,它会打印实例的 id(在整数的上下文中),这就是给您带来奇怪结果的原因。您必须向 viewTag 询问其整数值:

NSLog(@"The subView tag is %d", [viewTag intValue]);

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:

NSLog(@"The subView tag is %d", [viewTag intValue]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文