UITableView
添加新生成的随机字符串时,我需要对其进行排序。
我有这个代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addRandomString)];
self.navigationItem.rightBarButtonItem = addButton;
UIBarButtonItem *sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStyleBordered target:self action:@selector(sortStrings)];
self.navigationItem.leftBarButtonItem = sortButton;
stringsArray = [[NSMutableArray alloc]init];
int string_lenght = 10;
NSString *symbols = @"ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuvwxyz";
for (int y = 0; y<8; y++)
{
NSMutableString *randomString = [NSMutableString stringWithCapacity:string_lenght];
for (int i = 0; i<string_lenght; i++)
{
[randomString appendFormat:@"%C", [symbols characterAtIndex:random()%[symbols length]]];
}
[stringsArray addObject:randomString];
}
stringsForTableView = [[NSMutableArray alloc]initWithArray:stringsArray];
}
- (void) addRandomString {
int string_lenght = 10;
NSString *symbols = @"ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuvwxyz";
NSMutableString *randomString = [NSMutableString stringWithCapacity:string_lenght];
for (int i = 0; i<string_lenght; i++)
{
[randomString appendFormat:@"%C", [symbols characterAtIndex:random()%[symbols length]]];
}
[stringsForTableView addObject:randomString];
[self.tableView reloadData];
}
- (void) sortStrings{
??????????????????????
}
谢谢你的帮助!