思路

  • 这个简单的学生管理系统学生信息只有姓名,班级,年龄
  • 我在app执行时加了个开始界面,在AppDelegate.m 中将根视图设为需要显示的开机界面即可
  • 首先写登陆注册界面,注册需要查重,并转到登陆界面时要传值,传值可看我的这篇博客
  • 进入app后显示学生信息及要进行的操作,跳转界面即可

难点

  • 因为学生信息是统一的,执行过程中涉及到很多传值问题,正传反传一定要清楚
  • 查找时可以按姓名查找,按班级查找,按年龄查找;也可按班级和年龄查找等两者自由组合,也可三个一起查找

代码

我在这里放了每个功能的代码,推荐大家只看一个理解了就不必再看了,多了也繁琐,不如自己尝试,绝知此事要躬行嘛

因为界面比较多,为了方便理解,效果图就放在各段代码的后面
GitHub地址:学生管理系统

开始界面的设置(根视图的修改):
在AppDelegate.m 中修改方法 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];self.window.backgroundColor = [UIColor whiteColor];[self.window makeKeyWindow];ShowViewController *root = [[ShowViewController alloc] init];self.window.rootViewController = root;return YES;
}

然后在 ShowViewController.m 中:

#import "ShowViewController.h"
#import "LoadViewController.h"@interface ShowViewController ()@end@implementation ShowViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.UILabel *label = [[UILabel alloc] init];[self.view addSubview:label];label.text = @"学生管理系统";label.textColor = [UIColor whiteColor];label.frame = CGRectMake(0, 210, 414, 40);label.textAlignment = NSTextAlignmentCenter;label.font = [UIFont systemFontOfSize:27];UILabel *label1 = [[UILabel alloc] init];[self.view addSubview:label1];label1.text = @"TAY的";label1.textColor = [UIColor whiteColor];label1.frame = CGRectMake(0, 150, 414, 40);label1.textAlignment = NSTextAlignmentCenter;label1.font = [UIFont systemFontOfSize:38];UILabel *label2 = [[UILabel alloc] init];[self.view addSubview:label2];label2.text = @"TangAoyang's Student Management System";label2.numberOfLines = 0;label2.font = [UIFont systemFontOfSize:20];label2.textColor = [UIColor whiteColor];label2.frame = CGRectMake(0, 260, [UIScreen mainScreen].bounds.size.width, 30);label2.textAlignment = NSTextAlignmentCenter;UIImage *zyyImage = [UIImage imageNamed:@"zyy.jpg"];UIImageView *zyyImageView = [[UIImageView alloc] initWithImage:zyyImage];zyyImageView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height / 3, [UIScreen mainScreen].bounds.size.width, 280);[self.view addSubview:zyyImageView];self.view.backgroundColor = [UIColor blackColor];//两秒后执行函数//P1:需要执行的函数//P2:执行对象//P3:时间(单位是秒)[self performSelector:@selector(next) withObject:self afterDelay:2];}- (void)next {LoadViewController *root = [[LoadViewController alloc] init];self.view.window.rootViewController = root;}

效果:(两秒后跳转到登陆界面)

正式进来后首先是登陆界面
在LoadViewController.h 中:

#import <UIKit/UIKit.h>
#import "RegisterViewController.h"NS_ASSUME_NONNULL_BEGIN@interface LoadViewController : UIViewController
<
UITextFieldDelegate,
RegisterViewControllerDelegate
>@property UITextField *userTextField;
@property UITextField *passTextField;
@property UIButton *loadButton;
@property UIButton *registerButton;
@end

在 LoadViewController.m 中:

#import "LoadViewController.h"
#import "RegisterViewController.h"
#import "FirstViewController.h"@interface LoadViewController ()
<UITextFieldDelegate, RegisterViewControllerDelegate>{NSString *userStr;NSString *passStr;NSMutableArray *userArr;NSMutableArray *passArr;
}@end@implementation LoadViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.UIImage *backgroundImage = [UIImage imageNamed:@"背景7.jpg"];UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];backgroundImageView.frame = self.view.bounds;[self.view insertSubview:backgroundImageView atIndex:0];UIImage *lineImage = [UIImage imageNamed:@"竖线.png"];UIImageView *lineImageView = [[UIImageView alloc] initWithImage:lineImage];lineImageView.frame = CGRectMake(45, 10, 10, 30);UIImage *userImage = [UIImage imageNamed:@"用户.png"];UIImageView *userImageView = [[UIImageView alloc] initWithImage:userImage];userImageView.frame = CGRectMake(0, 0, 45, 45);UIView *user_View = [[UIView alloc] init];user_View.frame = CGRectMake(0, 0, 55, 50);[user_View addSubview:userImageView];[user_View addSubview:lineImageView];_userTextField = [[UITextField alloc] init];_userTextField.placeholder = @"请输入账号";_userTextField.textColor = [UIColor whiteColor];_userTextField.tintColor = [UIColor whiteColor];_userTextField.borderStyle = UITextBorderStyleLine;_userTextField.layer.masksToBounds = YES;_userTextField.layer.cornerRadius = 5;_userTextField.layer.borderWidth = 2;_userTextField.layer.borderColor = [UIColor whiteColor].CGColor;_userTextField.backgroundColor = [UIColor clearColor];[self.view addSubview:_userTextField];_userTextField.delegate = self;_userTextField.frame = CGRectMake(50, 370, 320, 55);_userTextField.keyboardType = UIKeyboardTypeDefault;_userTextField.leftViewMode = UITextFieldViewModeAlways;_userTextField.leftView = user_View;UIImageView *lineImageView2 = [[UIImageView alloc] initWithImage:lineImage];lineImageView2.frame = CGRectMake(45, 10, 10, 30);UIImage *passImage = [UIImage imageNamed:@"密码.png"];UIImageView *passImageView = [[UIImageView alloc] initWithImage:passImage];passImageView.frame = CGRectMake(0, 0, 45, 45);UIView *pass_View = [[UIView alloc] init];pass_View.frame = CGRectMake(0, 0, 55, 50);[pass_View addSubview:passImageView];[pass_View addSubview:lineImageView2];_passTextField = [[UITextField alloc] init];_passTextField.tintColor = [UIColor whiteColor];_passTextField.textColor = [UIColor whiteColor];_passTextField.placeholder = @"请输入密码";_passTextField.borderStyle = UITextBorderStyleRoundedRect;_passTextField.layer.masksToBounds = YES;_passTextField.layer.cornerRadius = 5;_passTextField.layer.borderWidth = 2;_passTextField.layer.borderColor = [UIColor whiteColor].CGColor;[self.view addSubview:_passTextField];_passTextField.backgroundColor = [UIColor clearColor];_passTextField.delegate = self;_passTextField.frame = CGRectMake(50, 450, 320, 55);_passTextField.keyboardType = UIKeyboardTypeDefault;_passTextField.secureTextEntry = YES;_passTextField.leftViewMode = UITextFieldViewModeAlways;_passTextField.leftView = pass_View;_loadButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];_loadButton.frame = CGRectMake(80, 525, 100, 35);_loadButton.titleLabel.font = [UIFont systemFontOfSize:23];[_loadButton setTitle:@"登陆" forState:UIControlStateNormal];[_loadButton addTarget:self action:@selector(pressLoad) forControlEvents:UIControlEventTouchDown];[self.view addSubview:_loadButton];_loadButton.tintColor = [UIColor whiteColor];_registerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:_registerButton];_registerButton.frame = CGRectMake(235, 525, 100, 35);_registerButton.titleLabel.font = [UIFont systemFontOfSize:23];_registerButton.tintColor = [UIColor whiteColor];[_registerButton setTitle:@"注册" forState:UIControlStateNormal];[_registerButton addTarget:self action:@selector(pressRegister) forControlEvents:UIControlEventTouchDown];userArr = [[NSMutableArray alloc] init];[userArr addObject:@"111"];[userArr addObject:@"222"];[userArr addObject:@"333"];[userArr addObject:@"444"];passArr = [[NSMutableArray alloc] init];[passArr addObject:@"aaa"];[passArr addObject:@"sss"];[passArr addObject:@"ddd"];[passArr addObject:@"fff"];}- (void)pressLoad{int i ;for(i = 0; i < userArr.count; i++) {if([_userTextField.text isEqualToString:userArr[i]] && [_passTextField.text isEqualToString:passArr[i]]) {FirstViewController *firstRoot = [[FirstViewController alloc] init];self.view.window.rootViewController = firstRoot;}}if(i == userArr.count){UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"账号与密码不匹配!" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleCancel handler:nil];[alert addAction:sureAction];[self presentViewController:alert animated:NO completion:nil];}
}- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {[self.view endEditing:YES];
}- (BOOL)textFieldShouldReturn:(UITextField *)textField {if(textField == _userTextField) {[_passTextField becomeFirstResponder];}if(textField == _passTextField) {[textField resignFirstResponder];}return YES;}- (void)pressRegister{RegisterViewController *registerViewController = [[RegisterViewController alloc] init];//反传的代理registerViewController.regiserViewControllerDelegate = self;//利用属性正传registerViewController.RuserArr = userArr;registerViewController.RpassArr = passArr;[self presentViewController:registerViewController animated:NO completion:nil];}
//协议方法
- (void)pass1:(NSString *)str1 pass2:(NSString *)str2 {_userTextField.text = str1;_passTextField.text = str2;}

登陆界面显示效果图:

密码与账号不匹配的警告:

下来是注册界面(注册完后返回登陆在登陆框上显示,如果有重复的账号显示提示框,并且未成功注册)
在 RegisterViewController.h 中:

#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@protocol RegisterViewControllerDelegate <NSObject>- (void)pass1:(NSString *)str1 pass2:(NSString *)str2;@end@interface RegisterViewController : UIViewController
<
UITextFieldDelegate
>@property (nonatomic, weak) id <RegisterViewControllerDelegate> regiserViewControllerDelegate;@property UITextField *messTextField;
@property UITextField *userTextField;
@property UITextField *passTextField;
@property NSMutableArray *RuserArr;
@property NSMutableArray *RpassArr;@end

在 RegisterViewController.m 中:

#import "RegisterViewController.h"@interface RegisterViewController (){NSArray *numArr;NSArray *nameArr;
}@end@implementation RegisterViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.UIImage *backgroundImage = [UIImage imageNamed:@"背景7.jpg"];UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];backgroundImageView.frame = self.view.bounds;[self.view insertSubview:backgroundImageView atIndex:0];UIImage *messImage = [UIImage imageNamed:@"邮箱.png"];UIImageView *messImageView = [[UIImageView alloc] initWithImage:messImage];messImageView.frame = CGRectMake(5, 0, 40, 40);UIImage *lineImage = [UIImage imageNamed:@"竖线.png"];UIImageView *lineImageView = [[UIImageView alloc] initWithImage:lineImage];lineImageView.frame = CGRectMake(45, 10, 10, 30);UIView *mess_View = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 55, 50)];[mess_View addSubview:lineImageView];[mess_View addSubview:messImageView];_messTextField = [[UITextField alloc] init];[self.view addSubview:_messTextField];_messTextField.delegate = self;_messTextField.tintColor = [UIColor whiteColor];_messTextField.textColor = [UIColor whiteColor];_messTextField.placeholder = @"请输入你的邮箱";_messTextField.layer.masksToBounds = YES;_messTextField.layer.cornerRadius = 5;_messTextField.layer.borderWidth = 2;_messTextField.frame = CGRectMake(50, 300, 300, 55);_messTextField.borderStyle = UITextBorderStyleRoundedRect;_messTextField.layer.borderColor = [UIColor whiteColor].CGColor;_messTextField.backgroundColor = [UIColor clearColor];_messTextField.leftViewMode = UITextFieldViewModeAlways;_messTextField.leftView = mess_View;UIImage *userImage = [UIImage imageNamed:@"用户.png"];UIImageView *userImageView = [[UIImageView alloc] initWithImage:userImage];userImageView.frame = CGRectMake(5, 0, 40, 40);UIImageView *lineView2 = [[UIImageView alloc] initWithImage:lineImage];lineView2.frame = CGRectMake(45, 10, 10, 30);UIView *user_View = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 55, 50)];[user_View addSubview:lineView2];[user_View addSubview:userImageView];_userTextField = [[UITextField alloc] init];[self.view addSubview:_userTextField];_userTextField.delegate = self;_userTextField.tintColor = [UIColor whiteColor];_userTextField.textColor = [UIColor whiteColor];_userTextField.placeholder = @"请输入账号";_userTextField.backgroundColor = [UIColor clearColor];_userTextField.frame = CGRectMake(50, 375, 300, 55);_userTextField.borderStyle = UITextBorderStyleRoundedRect;_userTextField.layer.masksToBounds = YES;_userTextField.layer.cornerRadius = 5;_userTextField.layer.borderWidth = 2;_userTextField.layer.borderColor = [UIColor whiteColor].CGColor;_userTextField.leftViewMode = UITextFieldViewModeAlways;_userTextField.leftView = user_View;UIImage *passImage = [UIImage imageNamed:@"密码.png"];UIImageView *passImageView = [[UIImageView alloc] initWithImage:passImage];passImageView.frame = CGRectMake(5, 0, 40, 40);UIImageView *lineImageView3 = [[UIImageView alloc] initWithImage:lineImage];lineImageView3.frame = CGRectMake(45, 10, 10, 30);UIView *pass_View = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 55, 50)];[pass_View addSubview:passImageView];[pass_View addSubview:lineImageView3];_passTextField = [[UITextField alloc] init];[self.view addSubview:_passTextField];_passTextField.delegate = self;_passTextField.secureTextEntry = YES;_passTextField.tintColor = [UIColor whiteColor];_passTextField.textColor = [UIColor whiteColor];_passTextField.placeholder = @"请输入密码";_passTextField.keyboardType = UIKeyboardTypeDefault;_passTextField.layer.masksToBounds = YES;_passTextField.layer.cornerRadius = 5;_passTextField.layer.borderWidth = 2;_passTextField.backgroundColor = [UIColor clearColor];_passTextField.frame = CGRectMake(50, 450, 300, 55);_passTextField.borderStyle = UITextBorderStyleRoundedRect;_passTextField.layer.borderColor = [UIColor whiteColor].CGColor;_passTextField.leftViewMode = UITextFieldViewModeAlways;_passTextField.leftView = pass_View;UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:button];[button setTitle:@"返回登陆" forState:UIControlStateNormal];button.titleLabel.font = [UIFont systemFontOfSize:23];button.tintColor = [UIColor whiteColor];button.layer.backgroundColor = [UIColor clearColor].CGColor;button.frame = CGRectMake(195, 530, 100, 50);[button addTarget:self action:@selector(pressBtn) forControlEvents:UIControlEventTouchDown];UIButton *Rbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:Rbutton];[Rbutton setTitle:@"注册" forState:UIControlStateNormal];Rbutton.titleLabel.font = [UIFont systemFontOfSize:23];Rbutton.tintColor = [UIColor whiteColor];Rbutton.layer.backgroundColor = [UIColor clearColor].CGColor;Rbutton.frame = CGRectMake(85, 530, 100, 50);[Rbutton addTarget:self action:@selector(pressRBtn) forControlEvents:UIControlEventTouchDown];}- (void)pressBtn{[self.view endEditing:YES];[self dismissViewControllerAnimated:NO completion:nil];//代理返回值if([_regiserViewControllerDelegate respondsToSelector:@selector(pass1:pass2:)]) {[_regiserViewControllerDelegate pass1:_userTextField.text pass2:_passTextField.text];}}- (void)pressRBtn{int i;//查重for(i = 0; i < _RuserArr.count; i++){if([_userTextField.text isEqualToString:_RuserArr[i]]){UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"账号重复!" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleCancel handler:nil];[alert addAction:sure];[self presentViewController:alert animated:NO completion:nil];break;}}//如果没有重复if(i == _RuserArr.count){UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"注册成功,请重新登录!" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleCancel handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];[_RuserArr addObject:_userTextField.text];[_RpassArr addObject:_passTextField.text];}
}
//按return键进入下一个textField
- (BOOL)textFieldShouldReturn:(UITextField *)textField {if(textField == _messTextField) {[_userTextField becomeFirstResponder];}if(textField == _userTextField){[_passTextField becomeFirstResponder];}if(textField == _passTextField){[textField resignFirstResponder];}return YES;}
//点击空白处键盘回收
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {[_messTextField endEditing:YES];[_passTextField endEditing:YES];[_userTextField endEditing:YES];}

注册效果图:

输入重复账号的警告:

下来就要正式进入app啦!
在这里,我定义一个储存信息的类 Student 来存学生信息(为了方便起见)
在 Student.h 中:

#import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGIN@interface Student : NSObject@property NSString *nameStr;
@property NSString *classStr;
@property NSString *ageStr;@end

增删改都自定义了协议(为了反传值),查不需要传值,故没有协议
进入后首页:
在 FirstViewController.h 中:

#import <UIKit/UIKit.h>
#import "AddViewController.h"
#import "DeleteViewController.h"
#import "ChangeViewController.h"
#import "Student.h"NS_ASSUME_NONNULL_BEGIN@class Student;
@interface FirstViewController : UIViewController
<
//增加的协议
addDelegate,
//删除的协议
DeleteDelegate,
//修改的协议
ChangeDelegate,
UITableViewDelegate,
UITableViewDataSource
>@property UITableView *tableView;
@property NSMutableArray *nameArr;
@property NSMutableArray *ageArr;
@property NSMutableArray *classArr;
@property NSMutableArray *stuArr;@end

在 FirstViewController.m 中:

#import "FirstViewController.h"
#import "FirstTableViewCell.h"
#import "AddViewController.h"
#import "DeleteViewController.h"
#import "ChangeViewController.h"
#import "FindViewController.h"
#import "Student.h"@interface FirstViewController ()@end@implementation FirstViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.UIImage *backImage = [UIImage imageNamed:@"背景10.jpg"];UIImageView *backImageView = [[UIImageView alloc] initWithImage:backImage];backImageView.frame = self.view.bounds;[self.view insertSubview:backImageView atIndex:0];_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 500) style:UITableViewStylePlain];[self.view addSubview:_tableView];_tableView.dataSource = self;_tableView.delegate = self;_tableView.backgroundColor = [UIColor clearColor];_tableView.tableFooterView = [[UIView alloc] init];[_tableView registerClass:[FirstTableViewCell class] forCellReuseIdentifier:@"111"];UIButton *addButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:addButton];addButton.frame = CGRectMake(100, 570, 100, 50);[addButton setTitle:@"add" forState:UIControlStateNormal];addButton.tintColor = [UIColor whiteColor];addButton.titleLabel.font = [UIFont systemFontOfSize:30];[addButton addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchDown];UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:deleteButton];deleteButton.frame = CGRectMake(250, 570, 100, 50);[deleteButton setTitle:@"delete" forState:UIControlStateNormal];deleteButton.tintColor = [UIColor whiteColor];deleteButton.titleLabel.font = [UIFont systemFontOfSize:30];[deleteButton addTarget:self action:@selector(delete) forControlEvents:UIControlEventTouchDown];UIButton *changeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:changeButton];changeButton.frame = CGRectMake(100, 640, 100, 50);[changeButton setTitle:@"change" forState:UIControlStateNormal];changeButton.tintColor = [UIColor whiteColor];changeButton.titleLabel.font = [UIFont systemFontOfSize:30];[changeButton addTarget:self action:@selector(change) forControlEvents:UIControlEventTouchDown];UIButton *findButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:findButton];findButton.frame = CGRectMake(250, 640, 100, 50);[findButton setTitle:@"find" forState:UIControlStateNormal];findButton.tintColor = [UIColor whiteColor];findButton.titleLabel.font = [UIFont systemFontOfSize:30];[findButton addTarget:self action:@selector(find) forControlEvents:UIControlEventTouchDown];UIButton *exitButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:exitButton];exitButton.frame = CGRectMake(250, 730, 100, 50);[exitButton setTitle:@"exit" forState:UIControlStateNormal];exitButton.tintColor = [UIColor whiteColor];exitButton.titleLabel.font = [UIFont systemFontOfSize:30];[exitButton addTarget:self action:@selector(exit) forControlEvents:UIControlEventTouchDown];_nameArr = [[NSMutableArray alloc] init];[_nameArr addObject:@"张三"];[_nameArr addObject:@"李四"];[_nameArr addObject:@"王麻子"];[_nameArr addObject:@"hahaha"];_ageArr = [[NSMutableArray alloc ]init];[_ageArr addObject:@"38"];[_ageArr addObject:@"250"];[_ageArr addObject:@"2"];[_ageArr addObject:@"123"];_classArr = [[NSMutableArray alloc] init];[_classArr addObject:@"a班"];[_classArr addObject:@"b班"];[_classArr addObject:@"c班"];[_classArr addObject:@"d班"];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"111" forIndexPath:indexPath];[cell give:indexPath Arr1:_nameArr Arr2:_ageArr Arr3:_classArr];return cell;}
//退出
- (void)exit{exit(0);
}
//tableView的行数根据学生数目来设
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return _nameArr.count;
}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{return 70;
}
//增加的点击事件
//这四个方法基本相同
- (void)add {AddViewController *addRoot = [[AddViewController alloc] init];//正传addRoot.nameArr = _nameArr;addRoot.ageArr = _ageArr;addRoot.classArr = _classArr;//反传的代理addRoot.addDelegate = self;[self presentViewController:addRoot animated:NO completion:nil];}
//删除的点击事件
- (void)delete {DeleteViewController *deleteRoot = [[DeleteViewController alloc] init];deleteRoot.nameArr = _nameArr;deleteRoot.ageArr = _ageArr;deleteRoot.classArr = _classArr;deleteRoot.deleteDelegate = self;[self presentViewController:deleteRoot animated:NO completion:nil];}
//修改的点击事件
- (void)change{ChangeViewController *changeRoot = [[ChangeViewController alloc] init];changeRoot.nameArr = _nameArr;changeRoot.ageArr = _ageArr;changeRoot.classArr = _classArr;changeRoot.changeDelegate = self;[self presentViewController:changeRoot animated:NO completion:nil];}
//查找的点击事件
- (void)find{FindViewController *findRoot = [[FindViewController alloc] init];findRoot.nameArr = _nameArr;findRoot.ageArr = _ageArr;findRoot.classArr = _classArr;[self presentViewController:findRoot animated:NO completion:nil];}
//增加的代理方法
- (void)pass:(Student *)student {[_nameArr addObject:student.nameStr];[_ageArr addObject:student.ageStr];[_classArr addObject:student.classStr];[_tableView reloadData];}
//删除的代理方法
- (void)deletepass1:(NSMutableArray *)nameArr pass2:(NSMutableArray *)ageArr pass3:(NSMutableArray *)classArr{_nameArr = nameArr;_ageArr = ageArr;_classArr = classArr;[_tableView reloadData];}
//修改的代理方法
- (void)changePass1:(NSMutableArray *)nameArr Pass2:(NSMutableArray *)ageArr Pass3:(NSMutableArray *)classArr{_nameArr = nameArr;_ageArr = ageArr;_classArr = classArr;[_tableView reloadData];}
//点击单元格不显示
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{[tableView deselectRowAtIndexPath:indexPath animated:NO];
}

tableview的cell:
在 FirstTableViewCell.h 中:

#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface FirstTableViewCell : UITableViewCell@property UILabel *nameLabel;
@property UILabel *classLabel;
@property UILabel *ageLabel;- (void)give:(NSIndexPath *)indexPath Arr1:(NSMutableArray *)nameArr Arr2:(NSMutableArray *)ageArr Arr3:(NSMutableArray *)classArr;@endNS_ASSUME_NONNULL_END

在 FirstTableViewCell.m 中:

#import "FirstTableViewCell.h"@implementation FirstTableViewCell
//为了方便,代码封装
- (void)give:(NSIndexPath *)indexPath Arr1:(NSMutableArray *)nameArr Arr2:(NSMutableArray *)ageArr Arr3:(NSMutableArray *)classArr {self.nameLabel.text = nameArr[indexPath.row];self.ageLabel.text = ageArr[indexPath.row];self.classLabel.text = classArr[indexPath.row];self.backgroundColor = [UIColor clearColor];
}- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];_nameLabel = [[UILabel alloc] init];[self.contentView addSubview:_nameLabel];_classLabel = [[UILabel alloc] init];[self.contentView addSubview:_classLabel];_ageLabel = [[UILabel alloc] init];[self.contentView addSubview:_ageLabel];return self;}- (void)layoutSubviews {[super layoutSubviews];_nameLabel.frame = CGRectMake(5, 25, 100, 20);_nameLabel.font = [UIFont systemFontOfSize:20];_nameLabel.textAlignment = NSTextAlignmentCenter;_nameLabel.textColor = [UIColor whiteColor];_classLabel.frame = CGRectMake(120, 25, 150, 20);_classLabel.font = [UIFont systemFontOfSize:20];_classLabel.textAlignment = NSTextAlignmentCenter;_classLabel.textColor = [UIColor whiteColor];_ageLabel.frame = CGRectMake(300, 25, 50, 20);_ageLabel.font = [UIFont systemFontOfSize:20];_ageLabel.textAlignment = NSTextAlignmentCenter;_ageLabel.textColor = [UIColor whiteColor];}- (void)awakeFromNib {[super awakeFromNib];// Initialization code
}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {[super setSelected:selected animated:animated];// Configure the view for the selected state
}

效果图:

增加:(具有查重,并且输入不能为空)
在 AddViewController.h 中:

#import <UIKit/UIKit.h>
#import "Student.h"NS_ASSUME_NONNULL_BEGIN
@class Student;
@protocol addDelegate <NSObject>- (void)pass: (Student *)student;@end@interface AddViewController : UIViewController
<
UITableViewDelegate,
UITableViewDataSource
>@property UITextField *nameTextField;
@property UITextField *classTextField;
@property UITextField *ageTextField;
@property NSMutableArray *nameArr;
@property NSMutableArray *ageArr;
@property NSMutableArray *classArr;
@property UITableView *tableView;
@property id <addDelegate> addDelegate;@end

在 AddViewController.m 中:

#import "AddViewController.h"
#import "FirstTableViewCell.h"@interface AddViewController ()@end@implementation AddViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.UIImage *backImage = [UIImage imageNamed:@"背景13.jpg"];UIImageView *backImageView = [[UIImageView alloc] initWithImage:backImage];backImageView.frame = self.view.bounds;[self.view insertSubview:backImageView atIndex:0];UIImage *nameImage = [UIImage imageNamed:@"姓名.png"];UIImageView *nameImageView = [[UIImageView alloc] initWithImage:nameImage];nameImageView.frame = CGRectMake(3, 3, 45, 45);_nameTextField = [[UITextField alloc] init];_nameTextField.layer.masksToBounds = YES;_nameTextField.layer.cornerRadius = 5;_nameTextField.layer.borderWidth = 2;_nameTextField.layer.borderColor = [UIColor whiteColor].CGColor;_nameTextField.tintColor = [UIColor whiteColor];_nameTextField.textColor = [UIColor whiteColor];_nameTextField.backgroundColor = [UIColor clearColor];_nameTextField.frame = CGRectMake(80, 500, 250, 50);_nameTextField.placeholder = @"请输入学生姓名";_nameTextField.leftViewMode = UITextFieldViewModeAlways;_nameTextField.leftView = nameImageView;[self.view addSubview:_nameTextField];UIImage *ageImage = [UIImage imageNamed:@"年龄.png"];UIImageView *ageImageView = [[UIImageView alloc] initWithImage:ageImage];ageImageView.frame = CGRectMake(3, 3, 45, 45);_ageTextField = [[UITextField alloc] initWithFrame:CGRectMake(80, 565, 250, 50)];[self.view addSubview:_ageTextField];_ageTextField.placeholder = @"请输入学生年龄";_ageTextField.layer.masksToBounds = YES;_ageTextField.layer.borderWidth = 2;_ageTextField.layer.cornerRadius = 5;_ageTextField.tintColor = [UIColor whiteColor];_ageTextField.textColor = [UIColor whiteColor];_ageTextField.backgroundColor = [UIColor clearColor];_ageTextField.layer.borderColor = [UIColor whiteColor].CGColor;_ageTextField.leftViewMode = UITextFieldViewModeAlways;_ageTextField.leftView = ageImageView;UIImage *classImage = [UIImage imageNamed:@"房子.png"];UIImageView *classImageView = [[UIImageView alloc] initWithImage:classImage];classImageView.frame = CGRectMake(3, 3, 45, 45);_classTextField = [[UITextField alloc] initWithFrame:CGRectMake(80, 630, 250, 50)];[self.view addSubview:_classTextField];_classTextField.placeholder = @"请输入学生班级";_classTextField.layer.masksToBounds = YES;_classTextField.layer.borderWidth = 2;_classTextField.layer.cornerRadius = 5;_classTextField.tintColor = [UIColor whiteColor];_classTextField.textColor = [UIColor whiteColor];_classTextField.backgroundColor = [UIColor clearColor];_classTextField.layer.borderColor = [UIColor whiteColor].CGColor;_classTextField.leftViewMode = UITextFieldViewModeAlways;_classTextField.leftView = classImageView;UIButton *add = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:add];add.frame = CGRectMake(110, 700, 80, 30);add.titleLabel.font = [UIFont systemFontOfSize:25];[add setTitle:@"完成" forState:UIControlStateNormal];add.backgroundColor = [UIColor clearColor];add.tintColor = [UIColor whiteColor];[add addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchDown];UIButton *back = [UIButton buttonWithType:UIButtonTypeRoundedRect];[self.view addSubview:back];back.frame = CGRectMake(250, 700, 80, 30);back.titleLabel.font = [UIFont systemFontOfSize:25];[back setTitle:@"返回" forState:UIControlStateNormal];back.backgroundColor = [UIColor clearColor];back.tintColor = [UIColor blackColor];[back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchDown];_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 2 - 100) style:UITableViewStylePlain];[self.view addSubview:_tableView];_tableView.dataSource = self;_tableView.delegate = self;_tableView.backgroundColor = [UIColor clearColor];_tableView.tableFooterView = [[UIView alloc] init];[_tableView registerClass:[FirstTableViewCell class] forCellReuseIdentifier:@"111"];//键盘上移[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"111" forIndexPath:indexPath];[cell give:indexPath Arr1:_nameArr Arr2:_ageArr Arr3:_classArr];return cell;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return _nameArr.count;
}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{return 70;
}- (void)add{//判断输入是否有空的if(_ageTextField.text.length <= 0 || _nameTextField.text.length <= 0 || _classTextField.text.length <= 0){UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"输入不能为空!" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleCancel handler:nil];[alert addAction:sure];[self presentViewController:alert animated:NO completion:nil];} else {int i;//查重for(i = 0; i< _nameArr.count; i++){if([_nameArr[i] isEqualToString:_nameTextField.text]){break;}}if(i != _nameArr.count){UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"姓名有重复,请核对后再试!" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleCancel handler:nil];[alert addAction:sure];[self presentViewController:alert animated:NO completion:nil];}if(i == _nameArr.count){[self dismissViewControllerAnimated:NO completion:nil];if([_addDelegate respondsToSelector:@selector(pass:)]) {Student *stu = [[Student alloc] init];stu.nameStr = _nameTextField.text;stu.ageStr = _ageTextField.text;stu.classStr = _classTextField.text;[_addDelegate pass:stu];}}}
}- (void)back {[self dismissViewControllerAnimated:NO completion:nil];
}- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{[_nameTextField endEditing:YES];[_ageTextField endEditing:YES];[_classTextField endEditing:YES];
}- (BOOL)textFieldShouldReturn:(UITextField *)textField {if(textField == _nameTextField) {[_ageTextField becomeFirstResponder];}if(textField == _ageTextField){[_classTextField becomeFirstResponder];}if(textField == _classTextField){[textField resignFirstResponder];}return YES;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{[tableView deselectRowAtIndexPath:indexPath animated:NO];
}-(void)keyboardWillShow : (NSNotification *)notify {CGFloat kbHeight = [[notify.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;CGFloat offset = kbHeight - 100;double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];if (offset > 0) {[UIView animateWithDuration:duration animations:^{self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height);}];}
}-(void)keyboardWillHide: (NSNotification *)notify {double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] doubleValue];[UIView animateWithDuration:duration animations:^{self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);}];
}
-(void)dealloc {[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

增加界面效果图:

查重:

判空:

删除界面:(可判断是否存在该学生)
在 DeleteViewController.h 中:

#import <UIKit/UIKit.h>
#import "Student.h"NS_ASSUME_NONNULL_BEGIN
@class Student;
@protocol DeleteDelegate <NSObject>- (void)deletepass1:(NSMutableArray *)nameArr pass2:(NSMutableArray *)ageArr pass3:(NSMutableArray *)classArr;@end
@interface DeleteViewController : UIViewController
<
UITableViewDataSource,
UITableViewDelegate
>@property UITextField *nameTextField;
@property UITableView *tableView;
@property NSMutableArray *nameArr;
@property NSMutableArray *ageArr;
@property NSMutableArray *classArr;
@property id <DeleteDelegate> deleteDelegate;@end

增删改查大同小异,下面三个我只放执行的核心代码了
在 DeleteViewController.m 中:

- (void)delete{//判断是否存在for(i = 0; i < _nameArr.count; i++){if([_nameArr[i] isEqualToString:_nameTextField.text]){UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"已找到此人,确认是否删除" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){[self delete2];}];UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:nil];[alert addAction:sure];[alert addAction:cancel];[self presentViewController:alert animated:NO completion:nil];break;}}//不存在if(i == _nameArr.count) {UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}}//删除操作
- (void)delete2{[_nameArr removeObjectAtIndex:i];[_ageArr removeObjectAtIndex:i];[_classArr removeObjectAtIndex:i];[self dismissViewControllerAnimated:NO completion:nil];if([_deleteDelegate respondsToSelector:@selector(deletepass1:pass2:pass3:)]){[_deleteDelegate deletepass1:_nameArr pass2:_ageArr pass3:_classArr];}
}

删除界面:

判断是否存在:

若存在操作:

删除后返回主界面:

修改:
因为修改需要先判断是否存在若存在再弹出输入修改信息的textField,故为了美观,我分为两个界面来写:

注意:在跳转到第二个界面时,第二个界面的nameTextField上的值应为第一个界面输入的值,且无法编辑。因为用户是使用该学生进入的,无法对别的学生进行操作

在 ChangeViewController.h 中:

#import <UIKit/UIKit.h>
#import "ChangeSonViewController.h"NS_ASSUME_NONNULL_BEGIN
@protocol ChangeDelegate <NSObject>- (void)changePass1:(NSMutableArray *)nameArr Pass2:(NSMutableArray *)ageArr Pass3:(NSMutableArray *)classArr;@end@interface ChangeViewController : UIViewController
<
ChangeSonDelegate,
UITableViewDataSource,
UITableViewDelegate
>@property UITextField *nameTextField;
@property UITableView *tableView;
@property NSMutableArray *nameArr;
@property NSMutableArray *ageArr;
@property NSMutableArray *classArr;
@property id <ChangeDelegate> changeDelegate;@end

在 ChangeViewController.m 中:
逻辑依旧是先判断是否存在,然后进行操作

- (void)change{int i;for(i = 0; i < _nameArr.count; i++){if([_nameArr[i] isEqualToString:_nameTextField.text]){break;}}if(i != _nameArr.count){UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"存在此人,是否继续修改" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleCancel handler:^(UIAlertAction *_Nonnull action){ChangeSonViewController *sonRoot = [[ChangeSonViewController alloc] init];sonRoot.nameArr = self->_nameArr;sonRoot.ageArr = self->_ageArr;sonRoot.classArr = self->_classArr;sonRoot.str = self->_nameTextField.text;sonRoot.changeSonDelegate = self;[self presentViewController:sonRoot animated:NO completion:nil];}];UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:nil];[alert addAction:cancel];[alert addAction:sure];[self presentViewController:alert animated:NO completion:nil];}if(i == _nameArr.count){UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}
}

判断有无效果图:

若存在,则跳转下一个界面:

在 ChangeSonViewController.h 中:

#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN
@protocol ChangeSonDelegate <NSObject>- (void)changeSonPass1:(NSMutableArray *)nameArr Pass2:(NSMutableArray *)ageArr Pass3:(NSMutableArray *)classArr;@end@interface ChangeSonViewController : UIViewController
<
UITextFieldDelegate
>@property UITextField *nameTextField;
@property UITextField *classTextField;
@property UITextField *ageTextField;
@property NSMutableArray *nameArr;
@property NSMutableArray *ageArr;
@property NSMutableArray *classArr;
@property NSString *str;
@property id <ChangeSonDelegate> changeSonDelegate;@end

在 ChangeSonViewController.m 中:
需要有三个textField

- (void)change{//找到该学生,将修改后的值赋给他int i;for(i = 0; i < _nameArr.count; i++){if([_nameArr[i] isEqualToString:_str]){[_ageArr replaceObjectAtIndex:i withObject:_ageTextField.text];[_classArr replaceObjectAtIndex:i withObject:_classTextField.text];}}if([_changeSonDelegate respondsToSelector:@selector(changeSonPass1:Pass2:Pass3:)]){[_changeSonDelegate changeSonPass1:_nameArr Pass2:_ageArr Pass3:_classArr];}[self dismissViewControllerAnimated:NO completion:nil];
}

效果图:
此处我将李四的信息修改:

点击完成:

修改成功!

最后是查找:
同样,因为要将找到的学生单独显示出来,我新建了一个界面,使用跳转

在 FindViewController.h 中:

#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN
@interface FindViewController : UIViewController
<
UITableViewDataSource,
UITableViewDelegate
>@property UITextField *nameTextField;
@property UITableView *tableView;
@property UITextField *classTextField;
@property UITextField *ageTextField;
@property NSMutableArray *nameArr;
@property NSMutableArray *ageArr;
@property NSMutableArray *classArr;
@property NSMutableArray *snameArr;
@property NSMutableArray *sageArr;
@property NSMutableArray *sclassArr;@end

在 FindViewController.m 中:

- (void)find{_snameArr = [[NSMutableArray alloc] init];_sageArr = [[NSMutableArray alloc] init];_sclassArr = [[NSMutableArray alloc] init];BOOL find = NO;int i = 0;int j;int t;if((_nameTextField.text.length > 0) && (_ageTextField.text.length <= 0) && (_classTextField.text.length <= 0)){for(i = 0; i < _nameArr.count; i++){if([_nameArr[i] isEqualToString:_nameTextField.text]){find = YES;[_snameArr addObject:_nameArr[i]];[_sageArr addObject:_ageArr[i]];[_sclassArr addObject:_classArr[i]];}}if(find == NO) {UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示"   message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}}if((_ageTextField.text.length > 0) && (_nameTextField.text.length <= 0) && (_classTextField.text.length <= 0)){for(j = 0; j < _ageArr.count; j++){if([_ageArr[j] isEqualToString:_ageTextField.text]){find = YES;[_snameArr addObject:_nameArr[j]];[_sageArr addObject:_ageArr[j]];[_sclassArr addObject:_classArr[j]];}}if(find == NO) {UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}}if((_classTextField.text.length > 0) && (_ageTextField.text.length <= 0) && (_nameTextField.text.length <= 0)){for(t = 0; t < _classArr.count; t++){if([_classArr[t] isEqualToString:_classTextField.text]){find = YES;[_snameArr addObject:_nameArr[t]];[_sageArr addObject:_ageArr[t]];[_sclassArr addObject:_classArr[t]];}}if(find == NO) {UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}}if((_nameTextField.text.length > 0) && (_ageTextField.text.length > 0) && (_classTextField.text.length <= 0)){for(i = 0; i < _nameArr.count; i++){if([_nameArr[i] isEqualToString:_nameTextField.text] && [_ageArr[i] isEqualToString:_ageTextField.text]){find = YES;[_snameArr addObject:_nameArr[i]];[_sageArr addObject:_ageArr[i]];[_sclassArr addObject:_classArr[i]];}}if(find == NO) {UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示"   message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}}if((_nameTextField.text.length > 0) && (_classTextField.text.length > 0) && (_ageTextField.text.length <= 0)){for(i = 0; i < _nameArr.count; i++){if([_nameArr[i] isEqualToString:_nameTextField.text] && [_classArr[i] isEqualToString:_classTextField.text]){find = YES;[_snameArr addObject:_nameArr[i]];[_sageArr addObject:_ageArr[i]];[_sclassArr addObject:_classArr[i]];}}if(find == NO) {UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示"   message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}}if((_classTextField.text.length > 0) && (_ageTextField.text.length > 0) && (_nameTextField.text.length <= 0)){for(i = 0; i < _nameArr.count; i++){if([_classArr[i] isEqualToString:_classTextField.text] && [_ageArr[i] isEqualToString:_ageTextField.text]){find = YES;[_snameArr addObject:_nameArr[i]];[_sageArr addObject:_ageArr[i]];[_sclassArr addObject:_classArr[i]];}}if(find == NO) {UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示"   message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}}if((_nameTextField.text.length > 0) && (_classTextField.text.length > 0) && (_ageTextField.text.length > 0)){for(i = 0; i < _nameArr.count; i++){if([_nameArr[i] isEqualToString:_nameTextField.text] && [_classArr[i] isEqualToString:_classTextField.text] && [_ageArr[i] isEqualToString:_ageTextField.text]){find = YES;[_snameArr addObject:_nameArr[i]];[_sageArr addObject:_ageArr[i]];[_sclassArr addObject:_classArr[i]];}}if(find == NO) {UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示"   message:@"没找到此人,请确认是否输入正确" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *sure1 = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:nil];[alert1 addAction:sure1];[self presentViewController:alert1 animated:NO completion:nil];}}if(find == YES){FindSonViewController *sonRoot = [[FindSonViewController alloc] init];sonRoot.nameArr = _snameArr;sonRoot.ageArr = _sageArr;sonRoot.classArr = _sclassArr;[self presentViewController:sonRoot animated:NO completion:nil];}
}

查询效果:

若存在,则直接跳转界面:
在 FindSonViewController.h 中:

#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface FindSonViewController : UIViewController
<
UITableViewDelegate,
UITableViewDataSource
>@property UILabel *label1;
@property UITableView *tableView;
@property NSMutableArray *nameArr;
@property NSMutableArray *ageArr;
@property NSMutableArray *classArr;@end

在 FindSonViewController.m 中:

- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.UIImage *backImage = [UIImage imageNamed:@"背景17.jpg"];UIImageView *backImageView = [[UIImageView alloc] initWithImage:backImage];backImageView.frame = self.view.bounds;[self.view insertSubview:backImageView atIndex:0];UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(60, 200, 300, 50)];label1.textColor = [UIColor whiteColor];label1.tintColor = [UIColor clearColor];label1.font = [UIFont systemFontOfSize:28];label1.text = @"您查找的学生信息为:";[self.view addSubview:label1];_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 290, [UIScreen mainScreen].bounds.size.width, 550) style:UITableViewStylePlain];[self.view addSubview:_tableView];_tableView.backgroundColor = [UIColor clearColor];_tableView.delegate = self;_tableView.dataSource = self;_tableView.tableFooterView = [[UIView alloc] init];[_tableView registerClass:[FindSonTableViewCell class] forCellReuseIdentifier:@"111"];UIButton *back = [UIButton buttonWithType:UIButtonTypeRoundedRect];back.frame = CGRectMake(180, 570, 200, 50);[self.view addSubview:back];[back setTitle:@"back" forState:UIControlStateNormal];back.titleLabel.font = [UIFont systemFontOfSize:25];back.tintColor = [UIColor whiteColor];back.backgroundColor = [UIColor clearColor];[back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchDown];}

使用tableView显示,在这里我强迫症,新建了一个cell,其实cell是和 FirstViewController 里 ableview 的cell一样,可用同一个,在这里就不再写了
找到后的界面:

如果有重复班级之内的:

这样,一个简单的学生管理系统就完啦

iOS 简单的学生管理系统(增删改查)相关推荐

  1. Java-GUI编程实战之管理系统 Day3【学生管理系统GUI设计、学生管理系统增删改查、项目MVC结构介绍、Java技能图谱】

    视频.课件.源码[链接:https://pan.baidu.com/s/13ffqGDzH-DZib6-MFViW3Q 提取码:zjxs] Java-GUI编程实战之管理系统 Day1[项目开发流程. ...

  2. C语言学生管理系统增删改查

    基于C语言和txt文件的增删改查 转载请注明出处 1.背景 本系统基于学生信息管理,完成了学生的信息的读取.增加.删除.修改.查询.本身意义可能不大,但是有很多学生再刚开始学习的时候,往往布置的大作业 ...

  3. java学生管理系统(增删改查存)

    说明: 1.期末结课做的简易的学生管理系统(java+mysql+excel+文本): 2.仅实现增删改查,显示,存储等界面操作: 实验报告如下: 1.数据库 2.需要添加额外的jar包(连接数据库或 ...

  4. python学生信息管理系统-增删改查-根据姓名查询

    学生信息管理系统 增删改查,求平均年龄,退出系统,根据姓名查询 def show_menu():print('*******欢迎使用学生管理系统*************')print('****** ...

  5. VS2019 C# MySQL 学生信息增删改查(二、改查(续前节))

    VS2019 C# MySQL 学生信息增删改查 六.改 1.在FormXiuGai界面中拖入控件,更改相应的属性,如下图所示. 思路:先查找,再将查找到的数据显示在TextBox上,再进行修改.我这 ...

  6. 基于springboot+thymeleaf+mybatis的员工管理系统 —— 增删改查

    员工管理系统 - 增删改查 entity 查询所有功能 查询所有的页面 emplist.html 保存员工 保存员工的页面 addEmp.html 删除员工 修改员工 根据id查询员工 修改员工信息 ...

  7. WEB阶段7:综合练习-联系人管理系统-增删改查查询分页

    综合练习-联系人管理系统-增删改查&查询分页 回顾 能够说出过滤器的作用 解决全局乱码问题 用户权限访问控制 用户输入文本内容进行过滤 能够编写过滤器 创建一个类实现javax.servlet ...

  8. Maynor手把手教你完成一个SpringBoot+Vue+Element实现的SPA商品管理系统(增删改查)

    Maynor手把手教你完成一个SpringBoot+Vue+Element实现的SPA商品管理系统(增删改查) 前言 完整代码 三连后私信我获取~ 撸了一上午完成的SPA商品管理系统,求三连! B站演 ...

  9. android 增删改查 源码_学生信息增删改查小程序案例(springboot服务端)

    项目描述: 该小程序实现了简单的管理员登录,学生信息添加,修改,删除,列表显示等功能,服务器端采用springboot框架提供接口,数据传输格式为json,适合新手学习小程序与服务端的交互,以及增删改 ...

最新文章

  1. 某资深互联网人分析:支付宝面临巨大困难,被微信争夺市场,年轻用户流失严重...
  2. strcmp可以比较数组么_005 继承、封装、多态及数组初识
  3. java开发流程图_Java 详解 JVM 工作原理和流程
  4. java 中如何实现多进程_在Java中可以使用哪些方法来实现Java的多进程运行模式?...
  5. java 怎么控制暂停5秒钟_java – libGDX暂停运行几秒钟
  6. Java解析excel表格
  7. 开源php todo,TODO:当PHP遇上IIS
  8. 重装ubuntu系统后VS Code远程连接失败
  9. fv-15php1c 安装图,SQLite - C/C++接口 API(一)
  10. Safari浏览器Session问题
  11. 聊聊flink JobManager的heap大小设置 1
  12. 9年经验,总结SEO职业瓶颈
  13. C语言学习7:ASCII码表及用法简介
  14. 2022年iOS面试题简答题
  15. 优化 | 运筹学:从入门到毕业
  16. 电脑状态栏中,声音图标不见了怎么办?三招帮你找回!
  17. Web前端大作业——城旅游景点介绍(HTML+CSS+JavaScript) html旅游网站设计与实现
  18. Android 点击键盘外 非输入框 关闭软键盘
  19. Windows 10安装AD远程服务器管理工具
  20. 《与大象共舞》读书笔记

热门文章

  1. 八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
  2. MiniGUI鼠标热插拔支持
  3. 济南电信dns服务器未响应,网页打不开?DNS解析失败?DNS服务器未响应?
  4. ubuntu20 deb包安装安装中心显示无法支持
  5. 基于微信小程序的党员之家服务系统小程
  6. css、HTML制作小米商城网页(三)
  7. YiBPM企业业务流程管理数字化升级,通过低代码平台如何实现?
  8. 安装linux系统磁盘阵列,Linux入门教程:磁盘阵列(RAID)
  9. 标定协议基础知识介绍
  10. vue初始化脚手架工程时npm报错