ios 错误:在“UIView *”类型的对象上找不到属性“frame”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16926239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: property 'frame' not found on object of type 'UIView *'
提问by HelenaM
I'm debugging my code and trying to figure out the size of the view using this:
我正在调试我的代码并尝试使用以下方法确定视图的大小:
p view.frame.size.height
but I'm getting this error:
但我收到此错误:
error: property 'frame' not found on object of type 'UIView *' error: 1 errors parsing expression
错误:在“UIView *”类型的对象上找不到属性“frame”错误:解析表达式时出现 1 个错误
any of you knows why or how can I debug the size of my view?
你们中的任何人都知道为什么或如何调试视图的大小?
回答by Chris Yim
If you hate typecasting every time, you can try this:
如果你讨厌每次都打字,你可以试试这个:
(lldb) expr @import UIKit
(lldb) po self.view.bounds
Since Xcode 7.2 is now available, I think we should update the answer.
I find the answer here, Why can't LLDB print view.bounds?
由于 Xcode 7.2 现在可用,我认为我们应该更新答案。
我在这里找到答案,为什么 LLDB 不能打印 view.bounds?
回答by Sanjit Saluja
Try this
尝试这个
p (CGRect)[view frame]
Alternative to get the frame of the view:
获取视图框架的替代方法:
po view
回答by Harshil
Try this,
尝试这个,
po view.layer.frame.size.height
回答by inix
it should have outer bracket in the first answer,like this:
它应该在第一个答案中有外括号,如下所示:
p ((CGRect)[cell frame])
output:
输出:
(CGRect) = origin=(x=0, y=0) size=(width=320, height=44)
回答by wj2061
Add a pch file , add these lines of code to the file:
添加一个 pch 文件,将这些代码行添加到文件中:
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#endif /* PrefixHeader_pch */
Next, link the pch file to your project:
接下来,将 pch 文件链接到您的项目:
Run the app again, then you should be able to use the dot notation in lldb console:
再次运行应用程序,然后您应该可以在 lldb 控制台中使用点表示法:
(lldb) po self.view.bounds
For how to add a pch file , see the answer here PCH File in Xcode 6
有关如何添加 pch 文件,请参阅此处的答案Xcode 6 中的 PCH 文件
回答by xindong
It seems that we cannot use dot notation in the console, try to use get method.
控制台中似乎不能使用点表示法,请尝试使用 get 方法。
回答by Gurjas
I had same problem and i solved it. Your class might be inherited from "UIViewController". It must be inherited from "UIView" so as to make an frame object in it.
我有同样的问题,我解决了它。您的类可能是从“UIViewController”继承的。它必须从“UIView”继承,以便在其中创建框架对象。