UI5_HomeWorkCompanyViewController
//
// 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的更多相关文章
随机推荐
- listen和accept函数
listen函数是用来设置监听连接的句柄和队列 当listen函数执行完成以后,服务端就已经可以接受客户端来的新连接了,新连接完成以后listen会把客户端的ip,port和连接句柄放在监听队列里面, ...
- 一款基于jQuery/CSS3实现拼图效果的相册
之前为大家介绍了 HTML5 3D立体图片相册, HTML5图片相册重力感应特效, 基于CSS3图片可倾斜摆放的动画相册 今天我们要来分享一款很酷的jQuery相册插件,首先相册中的图片会以一定的角度 ...
- 基于jQuery的网站首页宽屏焦点图幻灯片
今天给大家分享一款基于jQuery的网站首页宽屏焦点图幻灯片.这款焦点图适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗.效果图如下: 在线预览 ...
- 学了这四招,你在Linux上观看Netflix视频不发愁
导读 一份崭新的Linux发行版已经安装到你的电脑上,你完全准备好使用免费开源办公软件处理长时间的工作.但是你可能会问自己:"难道除了工作,就没有乐趣可言?我就是想观看Netflix视频!& ...
- php对比辨析之 mysql_escape_string & mysql_real_escape_string & addsalshes
概述: addslashes和mysql_real_escape_string.都是为了使数据安全的插入到数据库中而进行过滤. addslashes 转义的字符是单引号(').双引号("). ...
- 关于 ArtifactTransferException: Failure to transfer
eclipse 在导入maven project后,pom.xml有可能出现这种错误. 这里update maven project解决了:右键点击Maven项目->Maven->Upda ...
- python3.x爬取美团信息
在之前的文章中,笔者有提到,我们要在实践中去学习python,笔者有天就想着要不要爬点东西呢,跃跃欲试的节奏啊,想来想去,想到美团了,那么首先笔 者想给自己确定一个目标,就是我要爬什么样的数据,我要爬 ...
- Java基础知识强化之IO流笔记74:NIO之 Buffer
Java NIO中的Buffer用于和NIO通道进行交互.如你所知,数据是从通道读入缓冲区,从缓冲区写入到通道中的. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO ...
- 关于Django中的表单验证
ModelForm 和 普通的Form 都可以做表单验证 对于ModelForm如果只是想验证其中一部分model中的field,可以指定:内部类Meta的fields元素: fields = ('x ...
- 为DEDE织梦添加XMl网站地图
在后台管理: 核心-频道模型-单页文档管理-增加一个新页面 模版文件放在你现在使用的templets目录下,sitemap.xml的内容如下 <?xml version="1.0&qu ...