[cell viewWithTag:] 的奇怪问题
我刚刚分析了整个 iPhone 应用程序,然后收到逻辑错误。
UILabel *first_label = (UILabel *) [cell viewWithTag:1];
UILabel *second_label = (UILabel *) [cell viewWithTag:2];
[first_label setText:@"text"];
[second_label setText:@"text"];
NSLog(@"%@", first_label); // it exist
[first_label setFrame:CGRectMake(first_label.frame.origin.x, 10, 10, 10)];
我得到这个问题:
消息“frame”的接收者为 nil,并返回一个“CGRect”类型的值,该值将是垃圾
如果我改变的话,该值将是垃圾:
[first_label setFrame:CGRectMake(first_label.frame.origin.x, 10, 10, 10)];
他
[first_label setFrame:CGRectMake(10, 10, 10, 10)];
很高兴。正常吗?我可以毫无问题地获取标签,并且可以在任何地方使用它,但是当我尝试获取其框架时,它显示了这个问题。你有想法吗?
I've just analyzed the whole my iPhone app and I get a Logic Error.
UILabel *first_label = (UILabel *) [cell viewWithTag:1];
UILabel *second_label = (UILabel *) [cell viewWithTag:2];
[first_label setText:@"text"];
[second_label setText:@"text"];
NSLog(@"%@", first_label); // it exist
[first_label setFrame:CGRectMake(first_label.frame.origin.x, 10, 10, 10)];
I get this issue:
The receiver of message 'frame' is nil and returns a value of type 'CGRect' that will be garbage
If i change:
[first_label setFrame:CGRectMake(first_label.frame.origin.x, 10, 10, 10)];
with
[first_label setFrame:CGRectMake(10, 10, 10, 10)];
he's happy. Is it normal? I can get the label without problems and I can use it everywhere, but when I try to get its frame it says that issue. Have you ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分析器只是看到您在代码中没有添加带有标签 1 的视图的位置,这就是为什么
可能会返回 nil。只需在那里设置断点并检查返回值即可。如果它不为零,那么分析器可能无法理解代码中的某些内容,因为它也不完美。
Analyzer just sees that there is no place where you're adding the view with tag 1 in your code, and thats why
would probably return nil. Just set the breakpoint there and check the return value. If it is not nil, then probably analyzer doesn't understand something in your code, cause it's also not perfect.