Chr*_*ris 13 cocoa-touch objective-c nslog uitextview ios
I'm using NSLog to inspect a UITextView. I have the following logging statements in my code:
NSLog(@"textView: %@",textView);
NSLog(@"textView.frame: %@",textView.frame);
NSLog(@"[textView frame]: %@",[textView frame]);
Run Code Online (Sandbox Code Playgroud)
And in the output to the console, i get the following:
2010-11-29 22:00:38.252 MenuMaker[57602:207] textView: <UITextView: 0x3b3afe0; frame = (0 0; 320 387); text = 'blah...'; clipsToBounds = YES; autoresize = RM+BM; layer = <CALayer: 0x3b3afa0>>
2010-11-29 22:00:38.254 MenuMaker[57602:207] textView.frame: (null)
2010-11-29 22:00:38.254 MenuMaker[57602:207] [textView frame]: (null)
Run Code Online (Sandbox Code Playgroud)
The first line of output, since it contains the 'frame = (0 0; 320 387)' bit, leads me to believe that the UITextView's frame variable is all set up. But why do the next two lines show null in that case? Shouldn't they dump the frame's values?
Thanks in advance
小智 50
正如其他人所指出的那样,CGRect只是一个结构,因此缺少一个-description方法(这是NSLog使用的NSString的+ stringWithFormat静态方法 - 用格式字符串替换%@).因此,您无法直接将其传递给NSLog.
但是,不需要像建议的那样单独输出任何值.Cocoa提供了许多内置方法,可以将多个Core Graphics结构呈现为字符串:
NSStringFromCGRect()
NSStringFromCGPoint()
NSStringFromCGSize()
NSStringFromCGAffineTransform()
Run Code Online (Sandbox Code Playgroud)
等等.因此,以字符串的形式输出CGRect变得非常容易:
NSLog(@"%@", NSStringFromCGRect(rect));
Run Code Online (Sandbox Code Playgroud)
你可以找到所有这些辅助方法在这里下的"字符串转换".
Iph*_*rat 10
你也可以在下面这样做
NSLog(@"%@",[NSValue valueWithCGRect:textView.frame]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8101 次 |
| 最近记录: |