赋值使指针来自整数而不进行强制转换:地址问题
我想要我编写的每个图形组件的地址,以便稍后可以处理它,因为它是一个大矩阵,我不想这样做:“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先:无论你怎么做,迭代、操作和绘制 1000 个 UIView 可能会慢得令人无法接受。我敢打赌“绘图”部分将成为您的瓶颈,因此我怀疑迭代
subviews
数组或 2D C 数组之间的差异是否会在速度上产生显着差异。也就是说,要使警告消失,请将数组声明为
(UIView *)
指针数组而不是int
:然后您不需要执行任何类型随处投射。
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 ofint
:Then you don't need to do any type casting anywhere.
为什么不使用Tag属性,那么可以使用[self viewWithTag:aTag];
Why not use the Tag property, then you can use [self viewWithTag:aTag];
我不明白你在做什么,但直接回答,应该是
I cant understand what you are doing but straight to the answer, it should be