【发布时间】:2017-02-14 06:43:20
【问题描述】:
我有两个班级,即ViewController 和BViewController。
BViewController 类具有属性名称、地址和评级。
下面是ViewController.m的代码
如何在数组中排列对象,使它们按等级升序排列?另外,如何在视图中显示它们?
- (void)viewDidLoad {
[super viewDidLoad];
BViewController *b=[[BViewController alloc]init];
b.name=@"x";
b.address=@"bangalore";
b.rating=@6;
BViewController *c=[[BViewController alloc]init];
c.name=@"y";
c.address=@"bangalore";
c.rating=@5;
BViewController *d=[[BViewController alloc]init];
d.name=@"z";
d.address=@"bangalore";
d.rating=@7;
BViewController *e=[[BViewController alloc]init];
e.name=@"abc";
e.address=@"bangalore";
e.rating=@4;
BViewController *f=[[BViewController alloc]init];
f.name=@"xyz";
f.address=@"bangalore";
f.rating=@8;
}
【问题讨论】:
标签: objective-c sorting nsstring nsarray