ios - 在 NSArray 中排序对象?
<p><p>我有一个对象,如下</p>
<pre><code>#import <Foundation/Foundation.h>
@interface CountriesDAO : NSObject
@property (nonatomic, retain) NSString * countryname;
@end
#import "CountriesDAO.h"
@implementation CountriesDAO
@synthesize countryname;
@end
</code></pre>
<p>我已将它保存在 appDelegate 内的数组中。</p>
<pre><code>@property (nonatomic, retain) NSArray *countriesArray;
@synthesize countriesArray;
</code></pre>
<p>在另一个 Controller 中,我像获取它一样</p>
<pre><code>NSArray *countriesArray = appDelegate.countriesArray; It works fine and I get array.
</code></pre>
<p>当我尝试以这种方式对其进行排序时。</p>
<pre><code> NSArray *countriesArray1 = appDelegate.countriesArray;
NSSortDescriptor *valueDescriptor = [ initWithKey:@"countryname" ascending:YES];
NSArray * descriptors = ;
countriesArray = ;
</code></pre>
<p>我得到错误</p>
<pre><code>: unrecognized selector sent to instance 0xa83b4d0
2013-11-01 13:21:08.882 ECP *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-: unrecognized selector sent to instance 0xa83b4d0'
</code></pre>
<p>这里国家数组定义为</p>
<pre><code> @property (nonatomic, retain) NSArray *countriesArray;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我是这样做的,它对我有用。</p>
<pre><code>countriesArray = [ init];
for (CountriesDAO *info in appDelegate.countriesArray) {
;
}
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 在 NSArray 中排序对象?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19723218/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19723218/
</a>
</p>
页:
[1]