赋值使指针来自整数而不进行强制转换:地址问题

发布于 2024-11-09 06:50:37 字数 683 浏览 0 评论 0原文

我想要我编写的每个图形组件的地址,以便稍后可以处理它,因为它是一个大矩阵,我不想这样做:“for(UIView *myView in [self.view subviews]) {”。 <--链接速度太慢,而且我经常得不到我想要的东西。

但是,我可以通过保留地址并将指针地址设置为它来获得所需的结果,但我收到警告:

UIView *myView = [[UIView alloc] initWithFrame:RectFrame];
address[j][i] = (int) myView;
myView = address[j][i];   //  <---Assignment makes pointer from integer without a cast

好的,所以我尝试用 (UIView) 投射它并得到...

UIView *myView = [[UIView alloc] initWithFrame:RectFrame];
address[j][i] = (int) myView;
myView = (UIView) address[j][i];  //  <---Conversion to non-scalar type requested

那么我该如何安抚并清除警告“分配使指针来自整数而不进行强制转换”?

谢谢

I want the address for each graphic component I write so I can work off of it later as it is a large matrix and I don't want to do: "for(UIView *myView in [self.view subviews]){". <--too slow to link and often I don't get what I want.

However I can get the desired result by keeping the address and setting the pointer address to it, but I get a Warning:

UIView *myView = [[UIView alloc] initWithFrame:RectFrame];
address[j][i] = (int) myView;
myView = address[j][i];   //  <---Assignment makes pointer from integer without a cast

Ok, so I try and cast it with (UIView) and get...

UIView *myView = [[UIView alloc] initWithFrame:RectFrame];
address[j][i] = (int) myView;
myView = (UIView) address[j][i];  //  <---Conversion to non-scalar type requested

So how do I appease and clear the warning "ssignment makes pointer from integer without a cast" ??

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

捎一片雪花 2024-11-16 06:50:37

首先:无论你怎么做,迭代、操作和绘制 1000 个 UIView 可能会慢得令人无法接受。我敢打赌“绘图”部分将成为您的瓶颈,因此我怀疑迭代 subviews 数组或 2D C 数组之间的差异是否会在速度上产生显着差异。

也就是说,要使警告消失,请将数组声明为 (UIView *) 指针数组而不是 int

UIView *address[100][10];

然后您不需要执行任何类型随处投射。

First off: iterating, manipulating and drawing 1000 UIViews is probably going to be unacceptably slow no matter how you do it. And I'll bet the "drawing" part is going to be your bottleneck, so I doubt the difference between iterating through the subviews array or a 2D C array will make a noticeable difference in speed.

That said, to make the warning go away, declare your array as an array of (UIView *) pointers instead of int:

UIView *address[100][10];

Then you don't need to do any type casting anywhere.

短暂陪伴 2024-11-16 06:50:37

为什么不使用Tag属性,那么可以使用[self viewWithTag:aTag];

Why not use the Tag property, then you can use [self viewWithTag:aTag];

墨落画卷 2024-11-16 06:50:37

我不明白你在做什么,但直接回答,应该是

myView = (UIView *) address[j][i];

I cant understand what you are doing but straight to the answer, it should be

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