2013-03-23 22 views
0

我創建一個屬性字符串並有條件地應用刪除線。下面的代碼:NSAttributedString錯誤。它附加屬性字典的描述

NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init]; 
    if (needsStrikeThrough) { 
     [attributes setValue:[NSNumber numberWithInt:NSUnderlineStyleSingle] forKey:NSStrikethroughStyleAttributeName]; 
    } else { 
     [attributes setValue:[NSNumber numberWithInt:NSUnderlineStyleNone] forKey:NSStrikethroughStyleAttributeName]; 
    } 
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:participant.firstName attributes:attributes]; 
    NSLog(@"attString= %@", attString); 
    NSLog(@"[attributes description]= %@", [attributes description]); 

在控制檯的輸出是這樣的:

attributedParticipantName= Belinda{ 
    NSStrikethrough = 0; 
} 
[attributes description]= { 
    NSStrikethrough = 0; 
} 

所以字典的描述被附加到屬性串。任何想法爲什麼?

回答

1

這就是的description方法是如何實現的。它旨在幫助您進行調試,以便您可以在(純文本)控制檯中檢查字符串的屬性。實際的字符串只是大括號(「Belinda」)之前的部分。只打印字符串,沒有任何屬性,您可以登錄attString.string