给他人不同人

来源:互联网 发布:linux mount 本地目录 编辑:程序博客网 时间:2024/04/25 22:10


#import <Foundation/Foundation.h>


@interface Student : NSObject

@property (nonatomic,strong)NSString *stuName,*stuNumber,*stuTheory,*stuComputer,*stuRemarks;

@property (nonatomic,assign)NSInteger stuID;

@end




#import "AppDelegate.h"

#import "MyTableViewController.h"

@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    MyTableViewController *vc = [[MyTableViewControlleralloc]initWithStyle:UITableViewStyleGrouped];

    UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:vc];

    self.window.rootViewController = nav;

    returnYES;

}



#import "MyTableViewController.h"

#import "AddViewController.h"

#import "LoadData.h"

@interface MyTableViewController ()

{

    NSMutableArray *arr;

}

@end


@implementation MyTableViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    [[LoadDatashareLoadData]createTable];

    self.title =@"***";

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItemalloc]initWithTitle:@"***"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(addClicked)];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"查***"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(showAllData)];

}


-(void)viewDidAppear:(BOOL)animated{

    arr =[[LoadDatashareLoadData]showAllData];

    [self.tableViewreloadData];

}


-(void)addClicked{

    AddViewController *vc = [[AddViewControlleralloc]init];

    vc.idl =0;

    [self.navigationControllerpushViewController:vcanimated:YES];

}


#if 0


-(void)showAllData{

   //查询第一个数据

    arr = [[LoadData shareLoadData] showTop1Data];

    [self.tableView reloadData];

}


#elif 1


-(void)showAllData{

   //查询理论成绩最高的学生

    arr = [[LoadDatashareLoadData]showTheoryMaxData];

    [self.tableViewreloadData];

}


#elif 0


-(void)showAllData{

   //查询机试成绩最高的学生

    arr = [[LoadData shareLoadData] showComputerMaxData];

    [self.tableView reloadData];

}


#elif 0


-(void)showAllData{

   //删除理论成绩最低分的纪录

    arr = [[LoadData shareLoadData] deleteTheoryMinData];

    [self.tableView reloadData];

}


#endif


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

#warning Incomplete implementation, return the number of sections

    return1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

#warning Incomplete implementation, return the number of rows

    returnarr.count;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    staticNSString *str =@"cell";

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:str];

    if (!cell) {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleValue1reuseIdentifier:str];

    }

    cell.textLabel.text = [arr[indexPath.row]stuName];

    cell.detailTextLabel.text = [arr[indexPath.row]stuNumber];

    return cell;

}




// Override to support conditional editing of the table view.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

    // Return NO if you do not want the specified item to be editable.

    returnYES;

}



// Override to support editing the table view.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle ==UITableViewCellEditingStyleDelete) {

        [[LoadDatashareLoadData]deleteData:[arr[indexPath.row]stuID]];

        [arrremoveObjectAtIndex:indexPath.row];

        [self.tableViewreloadData];

    }

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    AddViewController *vc = [[AddViewControlleralloc]init];

    vc.idl =1;

    vc.st =arr[indexPath.row];

    [self.navigationControllerpushViewController:vcanimated:YES];

}




#import <UIKit/UIKit.h>

#import "Student.h"

#import "LoadData.h"

@interface AddViewController : UIViewController

@property (nonatomic,assign)NSInteger idl;

@property (nonatomic,strong)Student *st;

@end


}




@interface AddViewController ()

@property (weak,nonatomic)IBOutletUITextField *stuNameText;

@property (weak,nonatomic)IBOutletUITextField *stuNumberText;

@property (weak,nonatomic)IBOutletUITextField *stuTheoryText;

@property (weak,nonatomic)IBOutletUITextField *stuComputerText;

@property (weak,nonatomic)IBOutletUITextField *stuRemarksText;

@property (weak,nonatomic)IBOutletUIButton *addButton;


@end


@implementation AddViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view from its nib.

    if (self.idl ==0) {

        [_addButtonsetTitle:@"添加"forState:UIControlStateNormal];

    }else{

        self.stuNameText.text =self.st.stuName;

        self.stuNumberText.text = self.st.stuNumber;

        self.stuTheoryText.text = self.st.stuTheory;

        self.stuComputerText.text = self.st.stuComputer;

        self.stuRemarksText.text = self.st.stuRemarks;

        [_addButtonsetTitle:@"修改"forState:UIControlStateNormal];

    }

    

    

}

- (IBAction)AddData:(id)sender {

    

    if (self.idl ==0) {

        Student *stu = [[Studentalloc]init];

        stu.stuName =self.stuNameText.text;

        stu.stuNumber =self.stuNumberText.text;

        stu.stuTheory =self.stuTheoryText.text;

        stu.stuComputer =self.stuComputerText.text;

        stu.stuRemarks =self.stuRemarksText.text;

        [[LoadDatashareLoadData]addData:stu];

        [self.navigationControllerpopViewControllerAnimated:YES];

    }

    else{

        Student *stu = [[Studentalloc]init];

        stu.stuID =self.st.stuID;

        stu.stuName =self.stuNameText.text;

        stu.stuNumber =self.stuNumberText.text;

        stu.stuTheory =self.stuTheoryText.text;

        stu.stuComputer =self.stuComputerText.text;

        stu.stuRemarks =self.stuRemarksText.text;

        [[LoadDatashareLoadData]updateData:stu];

        [self.navigationControllerpopViewControllerAnimated:YES];

    }

}











1 0
原创粉丝点击