私は2つのクラス、すなわちViewController
とBViewController
を持っています。 BViewController
クラスには、名前、住所、および評価のプロパティがあります。以下はObjective-Cでのカスタムオブジェクトの配列の並べ替え
私は彼らが評価昇順で並べられていること、そのような配列内のオブジェクトを配置して行くにはどうすればよいViewController.m
ためのコードはありますか?さらに、それらをビューでどのように表示するのですか?お使いのアレイ
NSMutableArray *arrMain = [NSMutableArray arrayWithObjects:b, c, d, e ,f, nil];
今すぐソート評価
ホープ・テスト済みキー
NSArray *arrResult;
arrResult = [arrMain sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
NSNumber *first = [(BViewController*)a rating];
NSNumber *second = [(BViewController*)b rating];
NSComparisonResult result = [first compare:second];
return result;
}];
に基づいて、それはあなたをお手伝いします
- (void)viewDidLoad {
[super viewDidLoad];
BViewController *b=[[BViewController alloc]init];
[email protected]"x";
[email protected]"bangalore";
[email protected];
BViewController *c=[[BViewController alloc]init];
[email protected]"y";
[email protected]"bangalore";
[email protected];
BViewController *d=[[BViewController alloc]init];
[email protected]"z";
[email protected]"bangalore";
[email protected];
BViewController *e=[[BViewController alloc]init];
[email protected]"abc";
[email protected]"bangalore";
[email protected];
BViewController *f=[[BViewController alloc]init];
[email protected]"xyz";
[email protected]"bangalore";
[email protected];
}
storyBoardのようなstoryBoardのようなものを教えてもらえますか?結果を表示するには、フィールドフィールドやラベルが新しくなっています。 – taj
@taj入力には、UITextfieldsを使用します。並べ替え配列のUIButton結果値を表示するにはUILabelを押します。 –
ねえ、コンソールで出力を見るにはどうすればいいですか?私はNSLog(@ "%@"、arrResult)を置くので。 「」、「」、「」、「」、「」などの出力が表示されないこのように来ています –
taj