标签:
//
// YJPZViewController.m
// yuyetong
//
// Created by hong kangyan on 16/5/5.
// Copyright ? 2016年 ztld. All rights reserved.
//
#import "YJPZViewController.h"
extern NSMutableArray *arrayCS;
@interface YJPZViewController ()<UITextFieldDelegate>
//@property(nonatomic,strong)NSMutableArray *array;
@end
@implementation YJPZViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(@"^^^^^%@",arrayCS);
[self createLabel1];
[self createLabel];
[self createTextField];
[self createBarButton];
// [self.array removeAllObjects];
}
-(void)createLabel1{
for (int i=0; i<arrayCS.count; i++) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, (i * 70)+5, 100, 25)];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor grayColor];
NSString *str1 = @"最小值*:";
label.font = [UIFont systemFontOfSize:12];
label.text = [NSString stringWithFormat:@"%@%@",arrayCS[i],str1];
[self.view addSubview:label];
}
}
-(void)createLabel{
for (int i=0; i<arrayCS.count; i++) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, (i * 30)+40*(i+1), 100, 25)];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor grayColor];
NSString *str1 = @"最大值*:";
label.font = [UIFont systemFontOfSize:12];
label.text = [NSString stringWithFormat:@"%@%@",arrayCS[i],str1];
[self.view addSubview:label];
}
}
-(NSMutableArray *)array{
if (_array == nil) {
_array = [[NSMutableArray alloc]init];
}
return _array;
}
-(NSMutableString *)string{
if (_string == nil) {
_string = [[NSMutableString alloc]init];
}
return _string;
}
-(NSMutableString *)string1{
if (_string1 == nil) {
_string1 = [[NSMutableString alloc]init];
}
return _string1;
}
-(NSString *)str1{
if (_str1 == nil) {
_str1 = [[NSString alloc]init];
}
return _str1;
}
-(NSString *)str2{
if (_str2 == nil) {
_str2 = [[NSString alloc]init];
}
return _str2;
}
-(void)createTextField{
for(int i = 0; i < arrayCS.count * 2; i++) {
UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(115,(i * 35)+5 ,150 , 25)];
field.borderStyle = UITextBorderStyleRoundedRect;
field.backgroundColor = [UIColor grayColor];
field.textAlignment = UITextAlignmentCenter;
field.delegate = self;
field.tag = 100+i;
NSUserDefaults *mins = [NSUserDefaults standardUserDefaults];
NSString *min = [mins objectForKey:@"mins"];
NSUserDefaults *maxs = [NSUserDefaults standardUserDefaults];
NSString *max = [maxs objectForKey:@"maxs"];
NSArray * arrays1 = [min componentsSeparatedByString:@"/"];
NSArray *arrays2 = [max componentsSeparatedByString:@"/"];
NSLog(@"%@",arrays1);
NSLog(@"%@",arrays2);
NSMutableArray *a = [[NSMutableArray alloc]init];
for (int i = 0; i < arrays1.count; i++) {
[a addObject:arrays1[i]];
[a addObject:arrays2[i]];
}
field.text = a[i];
NSLog(@"%@",a);
field.clearButtonMode = UITextFieldViewModeAlways;
[self.view addSubview:field];
}
}
-(void)createBarButton{
UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target: self action:@selector(onClick:)];
self.navigationItem.rightBarButtonItem = item2;
}
-(void)onClick:(UIButton *)button{
self.string = nil;
self.string1 = nil;
for (int i = 0; i<arrayCS.count * 2; i++) {
UITextField *field = (id)[self.view viewWithTag:i+100];
if ((i + 2 ) %2 == 0) {
self.string = [self.string stringByAppendingFormat:@"%@%@",field.text,@"/"];
}
else if((i + 2 ) %2 != 0){
self.string1 = [self.string1 stringByAppendingFormat:@"%@%@",field.text,@"/"];
}
}
NSLog(@"========%@",self.string);
NSLog(@"========%@",self.string1);
self.str1 = [self.string substringToIndex:[self.string length] - 1];
self.str2 = [self.string1 substringToIndex:[self.string1 length] - 1];
NSLog(@"*****%@",self.string);
NSLog(@"*****%@",self.str1);
NSLog(@"*****%@",self.str2);
NSUserDefaults *mins = [NSUserDefaults standardUserDefaults];
NSUserDefaults *maxs = [NSUserDefaults standardUserDefaults];
[mins setObject:self.str1 forKey:@"mins"];
[maxs setObject:self.str2 forKey:@"maxs"];
[self yjpz];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder]; //主要是[receiver resignFirstResponder]在哪调用就能把receiver对应的键盘往下收
return YES;
}
//把TextField.text存储到数组中
-(void) textFieldDidEndEditing:(UITextField *)textField { //获取输入的内容
}
-(void)yjpz{
NSString *url = @"/fish/bind/bindqingmiao/update";
NSString *ids=[[YView getuserdata] objectForKey:@"id"];
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
[dic removeAllObjects];
[dic setObject:ids forKey:@"id"];
[dic setObject:self.str1 forKey:@"mins"];
[dic setObject:self.str2 forKey:@"maxs"];
NSLog(@">>>>>>%@",ids);
NSLog(@"%@",dic);
[[AFOSCClient sharedClient]postPath:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
isLoading = NO;
NSString *str3 = operation.responseString;
if ([self diaoxianjiancha:str3]) {
return ;
}
NSLog(@"%@",str3);
NSDictionary *jsondic = [str3 objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
BOOL result = [jsondic objectForKey:@"success"];
//NSLog(@"%c",result);
NSString *msg;
if (result) {
// msg=@"注册成功";
}else
{
// msg = [jsondic objectForKey:@"msg"];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"失败");
}];
}
- (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
标签:
原文地址:http://blog.csdn.net/delegate_m/article/details/51331366