//
// ItemCompany.h
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> @interface ItemCompany : NSObject @property (nonatomic, copy) NSString *companyName;
@property (nonatomic, copy) NSString *personName;
@property (assign,nonatomic) NSInteger money; @end //
// ItemCompany.m
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ItemCompany.h" @implementation ItemCompany @end
//
// ResultViewController.h
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ResultViewController : UIViewController - (void)showResult; @end //
// ResultViewController.m
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ResultViewController.h"
#import "AppDelegate.h"
#import "ItemCompany.h" @interface ResultViewController () @end @implementation ResultViewController
{
//AppDelegate *delegate;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect frame = self.view.frame;
frame.size.height = self.view.frame.size.height-100;
self.view.frame = frame;
//delegate =[[AppDelegate alloc] init];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-100)];
//label.backgroundColor= [UIColor cyanColor];
//label.alpha = 0.8;
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:24];
label.textColor = [UIColor blackColor];
label.text = @"显示结果:\n";
label.tag = 200;
[self.view addSubview:label]; self.view.backgroundColor = [UIColor whiteColor]; } - (void)showResult
{
UIApplication *app = [UIApplication sharedApplication];
AppDelegate *delegate = app.delegate;
NSString *str = @"";
//NSLog(@"%@",((ItemCompany *)[delegate.items objectAtIndex:0]).companyName);
for (ItemCompany *item in delegate.items) {
NSString *subStr = [NSString stringWithFormat:@"%@-%@-%li\n",item.companyName,item.personName,item.money];
str = [str stringByAppendingString:subStr];
}
UILabel *label = (UILabel *)[self.view viewWithTag:200];
label.text = str;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// CompanyViewController.h
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface CompanyViewController : UIViewController <UITextFieldDelegate> @end //
// CompanyViewController.m
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "CompanyViewController.h"
#import "AppDelegate.h"
#import "ItemCompany.h" @interface CompanyViewController () @end @implementation CompanyViewController
{
// UIApplication *app;
AppDelegate *delegate;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect frame = self.view.frame;
frame.size.height = self.view.frame.size.height-100;
self.view.frame = frame;
delegate =[[AppDelegate alloc] init];
// app = [UIApplication sharedApplication];
//delegate = delegate;
NSArray *textArray = @[@"公司名称",@"法人名称",@"注册资金"];
for (int i=0; i<3; i++) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100+80*i, 100, 50)];
//label.backgroundColor = [UIColor greenColor];
label.text = textArray[i];
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 100+80*i, self.view.frame.size.width-130, 50)];
textField.borderStyle = UITextBorderStyleRoundedRect;
NSString *holder = [NSString stringWithFormat:@"请输入%@", textArray[i]];
textField.placeholder = holder;
textField.returnKeyType = UIReturnKeyDone;
textField.tag = 200+i;
textField.delegate = self;
[self.view addSubview:textField];
} UIButton *saveBtn= [UIButton buttonWithType:UIButtonTypeSystem];
saveBtn.frame = CGRectMake(100, self.view.frame.size.height-60, self.view.frame.size.width-200, 40);
[saveBtn setTitle:@"保存" forState:UIControlStateNormal];
saveBtn.titleLabel.font = [UIFont systemFontOfSize:24];
[saveBtn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:saveBtn];
self.view.backgroundColor = [UIColor yellowColor]; } - (void)btnClicked
{
// UIApplication *app = [UIApplication sharedApplication];
// AppDelegate *delegate = app.delegate; ItemCompany *item = [[ItemCompany alloc] init];
item.companyName = ((UITextField *)[self.view viewWithTag:200]).text;
item.personName = ((UITextField *)[self.view viewWithTag:201]).text;
item.money = [((UITextField *)[self.view viewWithTag:202]).text integerValue]; if (item.companyName && item.personName) {
[delegate.items addObject:item];
}
NSLog(@"%@",((ItemCompany *)[delegate.items objectAtIndex:0]).companyName);
} #pragma mark ---UITextFieldDelegate--- - (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// AppDelegate.h
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h>
#import <CoreData/CoreData.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> //通过可变数组共享数据
@property (strong, nonatomic) NSMutableArray *items; @property (strong, nonatomic) UIWindow *window; @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; - (void)saveContext;
- (NSURL *)applicationDocumentsDirectory; @end //
// AppDelegate.m
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (instancetype)init
{
if (self = [super init]) {
self.items = [NSMutableArray array];
}
return self;
} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. return YES;
}
//
// ViewController.h
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end //
// ViewController.m
// UI5_HomeWork
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "ResultViewController.h"
#import "CompanyViewController.h" @interface ViewController ()
{
ResultViewController *_resultController;
CompanyViewController *_companyController;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_companyController = [[CompanyViewController alloc] init];
_resultController = [[ResultViewController alloc] init]; [self.view addSubview:_companyController.view];
[self.view addSubview:_resultController.view];
//设置view隐藏
_resultController.view.hidden = YES; NSArray *titles= @[@"公司",@"结果"];
CGFloat size = (self.view.frame.size.width-150)/2;
for (int i=0; i<2; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(50+(50+size)*i, self.view.frame.size.height-100+30, size, 40);
[btn setTitle:titles[i] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:24];
btn.tag = 200+i;
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
self.view.backgroundColor = [UIColor cyanColor];
} - (void)btnClicked:(UIButton *)btn
{
if (btn.tag==200) {
//公司
_companyController.view.hidden = NO;
_resultController.view.hidden = YES;
}
else if(btn.tag==201)
{
//结果
_companyController.view.hidden = YES;
_resultController.view.hidden = NO;
[_resultController showResult];
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UI5_HomeWorkCompanyViewController的更多相关文章

随机推荐

  1. Swift编程语言学习4.3—— 控制语句

    控制传递语句(Control Transfer Statements) 控制转移语句改变你代码的运行顺序,通过它你能够实现代码的跳转.Swift有四种控制转移语句. continue break fa ...

  2. innodb_io_capacity >=innodb_lru_scan_depth*inoodb_buffer_pool_instances。与 checkpoint

    innodb_lru_scan_depth:每个缓冲池刷脏页的能力 innodb_io_capacity:  iops inoodb_buffer_pool_instances=8 :缓冲池的个数 . ...

  3. 除去字符串中不相临的重复的字符 aabcad 得 aabcd

    假设有一个字符串aabcad,请编写一段程序,去掉字符串中不相邻的重复字符.即上述字串处理之后结果是为:aabcd; 分析,重点考查 char 与int 的隐式转换.程序如下: static void ...

  4. U_boot 的 bootcmd 和bootargs参数详解

    转自 :http://linux.chinaunix.net/bbs/archiver/tid-1111568.html U-boot的环境变量值得注意的有两个: bootcmd 和bootargs. ...

  5. 汇编中 .fill 的作用

    .fill     语法:.fill repeat, size, value    含义是反复拷贝 size个字节,重复 repeat 次,        其中 size 和 value 是可选的,默 ...

  6. Easier Done Than Said?

    Problem Description Password security is a tricky thing. Users prefer simple passwords that are easy ...

  7. LocalActivityManager的内部机制

    LocalActivityManager内部机制的核心在于,它使用了主线程对象mActivityThread来装载指定的Activity.注意,这里是装载,而不是启动,这点很重要. 所谓的启动,一般是 ...

  8. [转]epoll技术

    在linux的网络编程中,很长的时间都在使用select来做事件触发.在linux新的内核中,有了一种替换它的机制,就是epoll. 相比于select,epoll最大的好处在于它不会随着监听fd数目 ...

  9. iOS 画图讲解2

    1.图片水印 //layer上下文只能显示在drawRect里 //当开启上下文时,绘制图形即可在viewDidLoad中实现 //位图的上下文 //UIGraphicsBeginImageConte ...

  10. 重构5-Pull Up Field(字段上移)

    我们来看看一个和上移方法十分类似的重构.我们处理的不是方法,而是字段. public abstract class Account{} public class CheckingAccount ext ...