hi i am new iphone programmer i want to know
I get reciever type int
how can i sort the the generated random numbers? lowest to highest
I want to sort the numbers then show it in randomText.text
#import "RandomViewController.h"
@interface RandomViewController ()
@end
@implementation RandomViewController
int sortArr[5];
-(IBAction)btnRandom{
sortArr[0]= arc4random_uniform(5);
sortArr[1]=arc4random_uniform(5);
sortArr[2]=arc4random_uniform(5);
sortArr[3]=arc4random_uniform(5);
sortArr[4]=arc4random_uniform(5);
randomText.text=[NSString stringWithFormat: @"%i,%i,%i,%i,%i",sortArr[0],sortArr[1],sortArr[2],sortArr[3],sortArr[4]];
}
-(IBAction)btnClear{
randomText.text=@"";
sortedText.text=@"";
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: YES];
return [sortArr sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
}
@end
Aucun commentaire:
Enregistrer un commentaire