有了这个
NSSortDescriptor *lessonDescriptor = [[NSSortDescriptor alloc] initWithKey"lesson" ascending:YES];
[resultArray sortUsingDescriptors:[NSArray arrayWithObject:lessonDescriptor]];
它正在将“类(class)”对象排序为
(
{
lesson = 9;
subject = bg;
},
{
lesson = 8;
subject = bg;
},
{
lesson = 11;
subject = CAE;
},
{
lesson = 11;
subject = CAE;
},
{
lesson = 10;
subject = CAE;
},
{
lesson = 10;
subject = CAE;
},
{
lesson = 5;
subject = Gg;
},
{
lesson = 4;
subject = G;
},
{
lesson = 3;
subject = G;
},
{
lesson = 2;
subject = M;
},
{
lesson = 1;
subject = M;
}
)
如您所见,它的计数不正确。有人可以帮忙吗?
非常感谢
编辑:
不知道怎么实现值的东西=)
else if ([currentElement isEqualToString"lesson"])
{
NSString *trimmedString = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"trimmed: %@",trimmedString);
int value = [trimmedString intValue]; ??
[currentSummary appendString:value]; ??
[currentSummary appendString:trimmedString];
}
您必须在将“类(class)”转换为数字之前修剪字符串,以便排序描述符正常工作。否则,排序描述符只能看到字符串值而不是数字。这是删除空格和换行符的方法:
NSString *stringValue = [parsedValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
调用[stringValue intValue]会得到字符串的整数值
int value = [stringValue intValue];
在调用此属性的排序描述符之前将此值保存到数组中。
告诉我它是否有效。
关于iphone - NSSortDescriptor 根本无法计算数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3949294/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |