//
// 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. Skyline TerraExplorer Pro(等ActiveX控件)在Google Chrome浏览器的运行方法

    首先感谢ActiveX for Chrome 网银助手(np-activex)这个项目(https://code.google.com/p/np-activex/),解决了我们困惑很久的问题——在Ch ...

  2. svn cleanup failed–previous operation has not finished 解决方法

    今天svn遇到一个头疼的问题,最开始更新的时候失败了,因为有文件被锁住了.按照以往的操作,我对父目录进行clean up操作,但是clean up 操作也失败了! svn cleanup failed ...

  3. Android中如何实现多行、水平滚动的分页的Gridview?

    功能要求: (1)比如每页显示2X2,总共2XN,每个item显示图片+文字(点击有链接). 如果单行水平滚动,可以用Horizontalscrollview实现. 如果是多行水平滚动,则结合Grid ...

  4. EF 预热

    由于EF第一次加载比较慢,所以要对EF进行一次初始化的加载,类似第一次打开网页很慢,但第二次打开都很快了的原理一样:第一次把所有静态的图片和JS缓存到本地了:当第二次打开的时候都不需要再去下载这些东西 ...

  5. QT 操作数据库

    整理一下 QT 操作数据库的一些要点,以备以后的查询学习(主要是操作 mysql ). 首先,要查询相关的驱动是否已经装好了,可以用以下的程序进行验证: #include <QtCore/QCo ...

  6. nodejs配置与入门

    Node.js 笔记(一) nodejs.npm.express安装 http://blog.csdn.net/haidaochen/article/details/7257655 Windows平台 ...

  7. org.apache.hadoop.conf-Configuration

    终于遇到第一块硬骨头 Hadoop没有使用java.util.Properties管理配置文件,而是自己定义了一套配置文件管理系统和自己的API. package org.apache.hadoop. ...

  8. NLP自然语言处理学习笔记二(初试)

    前言: 用Python对自然语言处理有很好的库.它叫NLTK.下面就是对NLTK的第一尝试. 安装: 1.安装Pip 比较简单,得益于CentOS7自带的easy_install.执行一行命令就可以搞 ...

  9. IOS NS 字符串 数组 字典 文件 动态 静态 操作

    ios 常用字符串的操作   //将NSData转化为NSString        NSString* str = [[NSString alloc] initWithData:response e ...

  10. [Java] JSTL格式化时间计算时差

    引入JSLT标签: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> ...