ios - (NSDictionary *) labelAttrs = 0x00000001

标签 ios objective-c

做一些调试我打印出一个 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

enter image description here

这是它之前在 Xcode 中的样子:

enter image description here

然后当我跨过去时:

enter image description here

注意:这给了我同样的崩溃:

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/

相关文章:

ios - 不清楚释放 CFDictionaryRef

javascript - 将 PFQueries 的上限更改为 1000 以上

objective-c - 处理图像时出现 Retina 显示问题

iphone - UITableView开始滚动位置

objective-c - 关于autorelease/release和【池释放】

ios - 理解授权和协议(protocol)之间的关系

ios - 为什么我在 swift 中看不到响应值?

ios - Xcode 44生成的dsym文件中没有UUID

ios - 如何在可调整大小的 UITableviewCell 中添加 UITextView

ios - 在两个可移动 uiview 之间画线