简单的NSTextList问题 [英] Simple NSTextList question
本文介绍了简单的NSTextList问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用 NSTextList
在多行 NSTextField
中显示数字列表,但它不是
$ b (IBAction)displayResult:(id)sender
{
NSTextList * list = [[NSTextList alloc] initWithMarkerFormat:self.markerFormat options:1]; // {Decimal}以标记格式传递
NSMutableParagraphStyle * paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraph setTextLists:[NSArray arrayWithObject:list]];
[list release];
NSDictionary * attributes = [NSDictionary dictionaryWithObjectsAndKeys:paragraph,NSParagraphStyleAttributeName,nil];
NSAttributedString * attrString = [[NSAttributedString alloc] initWithString:self.inputString attributes:attributes]; // input string is- George \\\
Thomas \\\
Ashok
[self setOutputString:attrString];
[attrString release];
[paragraph release];
}
输入为 -
George
Thomas
Ashok
输出应为 -
1 George
2 Thomas
3 Ashok
但输出显示is -
George
Thomas
Ashok
任何人都可以建议如何实现预期的输出?
解决方案您正在做的一切看起来都很好,华丽地给我:)
输入字符串有一个问题
尝试这个,NSTextList * list1 = [[NSTextList alloc] initWithMarkerFormat:@{decimal}options:0]; // {Decimal}以标记格式传递
NSMutableParagraphStyle * paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[list1 setStartingItemNumber:1];
[paragraph setTextList:[NSArray arrayWithObject:list1]];
NSDictionary * attributes = [NSDictionary dictionaryWithObjectsAndKeys:paragraph,NSParagraphStyleAttributeName,nil];
NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@\t%@ Suhas \\\
\t%@ Devarshi \\\
\t%@ Rohith\\\
, [list1 markerForItemNumber:1],[list1 markerForItemNumber:2],[list1 markerForItemNumber:3]] attributes:attributes];
[self.text setStringValue:attrString]; // self.text是一个NSTextField实例。请仔细忽略编译器警告:)
I am trying to use
NSTextList
to display a numeric list in a multi-lineNSTextField
but it is not working as intended.The sample code used is:
- (IBAction)displayResult:(id)sender { NSTextList *list = [[NSTextList alloc] initWithMarkerFormat:self.markerFormat options:1]; // {Decimal} passed as marker format NSMutableParagraphStyle *paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [paragraph setTextLists:[NSArray arrayWithObject:list]]; [list release]; NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:paragraph, NSParagraphStyleAttributeName, nil]; NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:self.inputString attributes:attributes] ; // input string is- George \n Thomas \n Ashok [self setOutputString:attrString]; [attrString release]; [paragraph release]; }
The input is -
George Thomas Ashok
The output should be -
1 George 2 Thomas 3 Ashok
but output it is showing is -
George Thomas Ashok
Can anyone suggest how to achieve the expected output?
解决方案Everything you are doing looks fine and ornately to me:) There is a problem with your input string Try this,
NSTextList *list1 = [[NSTextList alloc] initWithMarkerFormat:@"{decimal}" options:0]; // {Decimal} passed as marker format NSMutableParagraphStyle *paragraph = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [list1 setStartingItemNumber:1]; [paragraph setTextLists:[NSArray arrayWithObject:list1]]; NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:paragraph, NSParagraphStyleAttributeName, nil]; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\t%@ Suhas \n \t%@ Devarshi \n \t%@ Rohith\n", [list1 markerForItemNumber:1],[list1 markerForItemNumber:2],[list1 markerForItemNumber:3]] attributes:attributes] ; [self.text setStringValue:attrString];//self.text is a NSTextField instance. kindly ignore the compiler warning:)
这篇关于简单的NSTextList问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文