- (void)pressAdd {
int bool1 = 0;
int bool2 = 1;
NSString* name = _nameText.text;
NSString* class = _classText.text;
NSString* mark = _markText.text;
int x = [mark intValue];
if ([name isEqualToString:@""] || [class isEqualToString:@""] || [mark isEqualToString:@""] || x > 150 || x < 0) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"输入错误!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:sure];
[self presentViewController:alertController animated:YES completion:nil];
_nameText.text = nil;
_classText.text = nil;
_markText.text = nil;
bool2 = 0;
}
for (int i = 0; i < _array1.count; i ++) {
if ([class isEqualToString: _array2[i]]) {
if ([name isEqualToString:_array1[i]]) {
bool1 = 1;
break;
}
}
}
if (bool1 == 1) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"该班级已存在该学生" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:sure];
[self presentViewController:alertController animated:YES completion:nil];
} else if (bool2 == 1 && bool1 == 0){
[_array1 addObject:name];
[_array2 addObject:class];
[_array3 addObject:mark];
[_delegate addMessage:_array1 :_array2 :_array3];
[self dismissViewControllerAnimated:YES completion:nil];
// [self.navigationController popViewControllerAnimated:YES];
// FristViewController* v1 = [[FristViewController alloc] init];
// [self. navigationController pushViewController:v1 animated:YES];
}
_nameText.text = nil;
_classText.text = nil;
_markText.text = nil;
}
- (void)pressFind {
int bool1 = 0;
NSString* name = _nameText.text;
// NSString* class = _classText.text;
if ([name isEqualToString:@""]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"输入不能为空!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:sure];
[self presentViewController:alertController animated:YES completion:nil];
}
int i;
_array = [[NSMutableArray alloc] init];
for (i = 0; i < _array1.count; i ++) {
// if ([class isEqualToString: _array2[i]]) {
if ([name isEqualToString:_array1[i]]) {
bool1 = 1;
// break;
NSString* str = [NSString stringWithFormat:@"%d", i];
[_array addObject:str];
}
// }
}
NSLog(@"count %ld", _array.count);
if (bool1 == 1) {
for (int j = 1; j < _array.count + 1; j ++) {
int intStr = [_array[j - 1] intValue];
UILabel* nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 70 * j, 100, 40)];
nameLabel.text = _array1[intStr];
nameLabel.textColor = [UIColor whiteColor];
nameLabel.font = [UIFont systemFontOfSize:21];
[self.view addSubview:nameLabel];
UILabel* classLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 70 * j, 100, 40)];
classLabel.text = _array2[intStr];
classLabel.textColor = [UIColor whiteColor];
classLabel.font = [UIFont systemFontOfSize:21];
[self.view addSubview:classLabel];
UILabel* markLabel = [[UILabel alloc] initWithFrame:CGRectMake(240, 70 * j, 100, 40)];
markLabel.text = _array3[intStr];
markLabel.textColor = [UIColor whiteColor];
markLabel.font = [UIFont systemFontOfSize:21];
[self.view addSubview:markLabel];
」
_nameText.text = nil;
_classText.text = nil;
} else {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"查询驳回,检查输入是否有误" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertControl}er addAction:sure];
[self presentViewController:alertController animated:YES completion:nil];
}
}
- (void)pressChange {
int bool1 = 0;
NSString* name = _nameText.text;
if ([name isEqualToString:@""]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"输入不能为空!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:sure];
[self presentViewController:alertController animated:YES completion:nil];
}
int i;
for (i = 0; i < _array1.count; i ++) {
if ([name isEqualToString: _array1[i]]) {
if ([name isEqualToString:_array1[i]]) {
bool1 = 1;
break;
}
}
}
这里的思路比较简单,刚开始我一直在纠结OC自带的排序那种才能用,后来其实借鉴了C语言学生管理系统的思路,直接冒泡排序,然后三个数组的索引是一样的,都一交换即可完成排序
相关代码较简单不与展示