Unable to get the exact tag value of a UIView
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开发者_StackOverflow社区 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??
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
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]);
精彩评论