iphone - NSSortDescriptor 根本无法计算数字
<p><p>有了这个</p>
<pre><code> NSSortDescriptor *lessonDescriptor = [ initWithKey:@"lesson" ascending:YES];
];
</code></pre>
<p>它正在将“类(class)”对象排序为 </p>
<pre><code>(
{
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;
}
</code></pre>
<p>)</p>
<p>如您所见,它的计数不正确。有人可以帮忙吗?</p>
<p>非常感谢</p>
<p>编辑:</p>
<p>不知道怎么实现值的东西=) </p>
<pre><code>else if ()
{
NSString *trimmedString = ];
NSLog(@"trimmed: %@",trimmedString);
int value = ; ??
;??
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您必须在将“类(class)”转换为数字之前修剪字符串,以便排序描述符正常工作。否则,排序描述符只能看到字符串值而不是数字。这是删除空格和换行符的方法:</p>
<pre><code>NSString *stringValue = ];
</code></pre>
<p>调用会得到字符串的整数值</p>
<pre><code>int value = ;
</code></pre>
<p>在调用此属性的排序描述符之前将此值保存到数组中。</p>
<p>告诉我它是否有效。</p></p>
<p style="font-size: 20px;">关于iphone - NSSortDescriptor 根本无法计算数字,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/3949294/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/3949294/
</a>
</p>
页:
[1]