- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
做一些调试我打印出一个 NSDictionary 变量的描述,它给出了这个:
(NSDictionary *) labelAttrs = 0x00000001
有人可以解释为什么这是 1
吗?
我会理解 nil
或对象指针,但为什么是 1
?
更新
代码:
NSDictionary *labelAttrs = @{NSForegroundColorAttributeName:[UIColor darkGrayColor]};
它在 iOS5 上运行时崩溃,但在 iOS6 上运行时不会崩溃,但是:
Are the new object literals backwards compatible with iOS 5?
似乎是说您可以在 iOS5 中使用新文字(只要您针对 iOS6 进行构建并使用 Xcode >= 4.5 并使用最新的 LLVM 进行编译 - 例如,请参阅屏幕抓图)。而且,根据 Apple 的说法,我应该可以使用它们:https://developer.apple.com/library/ios/#releasenotes/ObjectiveC/ObjCAvailabilityIndex/index.html
这是它之前在 Xcode 中的样子:
然后当我跨过去时:
注意:这给了我同样的崩溃:
NSDictionary *labelAttrs = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], NSForegroundColorAttributeName, [UIFont fontWithName:CUSTOMFONT size:size], NSFontAttributeName, [NSNumber numberWithInt:0], NSStrokeWidthAttributeName, nil];
删除此代码(以及以下两行代码)意味着该应用程序可以运行而不会崩溃。但显然没有属性字符串。
更新:已解决。属性字符串在 iOS5 上不可用(至少对于 UILabel 而言):Is NSAttributedString available before iOS 6?
最佳答案
问题是 NSAttributedString UIKit additions在 iOS 6 之前不可用。这意味着常量 NSForegroundColorAttributeName 等未定义。因此,字典的创建在尝试引用这些内容时失败了。
(调试它的方法——除了检查错误 iOS 版本的引用 (;))——是分解语句:
UIColor* value1 = [UIColor darkGrayColor];
NSString* key1 = NSForegroundColorAttributeName;
UIFont* value2 = [UIFont fontWithName:CUSTOMFONT size:size];
NString* key2 = NSFontAttributeName;
NSNumber* value3 = [NSNumber numberWithInt:0];
NSString* key3 = NSStrokeWidthAttributeName;
NSDictionary *labelAttrs0 = [NSDictionary dictionaryWithObjectsAndKeys:nil];
NSDictionary *labelAttrs1 = [NSDictionary dictionaryWithObjectsAndKeys:value1, key1, nil];
NSDictionary *labelAttrs2 = [NSDictionary dictionaryWithObjectsAndKeys:value2, key2, nil];
NSDictionary *labelAttrs3 = [NSDictionary dictionaryWithObjectsAndKeys:value3, key3, nil];
然后看看失败的地方。在这种情况下,您可能会在分配 labelAttrs1 时失败。如果你然后是 NSLog value1 和 key1 你会在 key1 上得到一个错误。)
关于ios - (NSDictionary *) labelAttrs = 0x00000001,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15504556/
做一些调试我打印出一个 NSDictionary 变量的描述,它给出了这个: (NSDictionary *) labelAttrs = 0x00000001 有人可以解释为什么这是 1 吗? 我会理
我是一名优秀的程序员,十分优秀!