[cell viewWithTag:] 的奇怪问题

发布于 2024-12-15 09:35:52 字数 755 浏览 2 评论 0原文

我刚刚分析了整个 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 技术交流群。

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

发布评论

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

评论(1

Oo萌小芽oO 2024-12-22 09:35:52

分析器只是看到您在代码中没有添加带有标签 1 的视图的位置,这就是为什么

UILabel *first_label = (UILabel *) [cell viewWithTag: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

UILabel *first_label = (UILabel *) [cell viewWithTag:1]; 

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.

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