简单的textField 应用 逻辑很混乱。

来源:互联网 发布:91永久域名 编辑:程序博客网 时间:2024/05/17 04:37

//

//  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 {

    [superviewDidLoad];

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

    NSLog(@"^^^^^%@",arrayCS);

    [selfcreateLabel1];

    [selfcreateLabel];

    [selfcreateTextField];

    [selfcreateBarButton];

//    [self.array removeAllObjects];

    

  

}

-(void)createLabel1{

    for (int i=0; i<arrayCS.count; i++) {

        UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(5, (i *70)+5,100, 25)];

        label.textColor = [UIColorblackColor];

        label.backgroundColor = [UIColorgrayColor];

        NSString *str1 =@"最小值*:";

        label.font = [UIFontsystemFontOfSize:12];

  

        label.text = [NSStringstringWithFormat:@"%@%@",arrayCS[i],str1];

      

        [self.viewaddSubview:label];

        

    }


}

-(void)createLabel{

    for (int i=0; i<arrayCS.count; i++) {

        UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(5, (i *30)+40*(i+1),100, 25)];

        label.textColor = [UIColorblackColor];

        label.backgroundColor = [UIColorgrayColor];

        NSString *str1 =@"最大值*:";

        label.font = [UIFontsystemFontOfSize:12];

        label.text = [NSStringstringWithFormat:@"%@%@",arrayCS[i],str1];

        

        [self.viewaddSubview:label];

        

    }


}

-(NSMutableArray *)array{

    if (_array ==nil) {

        _array = [[NSMutableArrayalloc]init];

        

    }

    return_array;

    

}

-(NSMutableString *)string{

    if (_string ==nil) {

        _string = [[NSMutableStringalloc]init];

        

    }

    return_string;

    

}

-(NSMutableString *)string1{

    if (_string1 ==nil) {

        _string1 = [[NSMutableStringalloc]init];

        

    }

    return_string1;

    

}

-(NSString *)str1{

    if (_str1 ==nil) {

        _str1 = [[NSStringalloc]init];

        

    }

    return_str1;

    

}

-(NSString *)str2{

    if (_str2 ==nil) {

        _str2 = [[NSStringalloc]init];

        

    }

    return_str2;

    

}

-(void)createTextField{

    for(int i =0; i < arrayCS.count *2; i++) {

        UITextField *field = [[UITextFieldalloc]initWithFrame:CGRectMake(115,(i *35)+5 ,150 ,25)];

        field.borderStyle =UITextBorderStyleRoundedRect;

        field.backgroundColor = [UIColorgrayColor];

        field.textAlignment =UITextAlignmentCenter;

        field.delegate =self;

        field.tag =100+i;

        NSUserDefaults *mins = [NSUserDefaultsstandardUserDefaults];

        NSString *min = [minsobjectForKey:@"mins"];

        NSUserDefaults *maxs = [NSUserDefaultsstandardUserDefaults];

        NSString *max = [maxsobjectForKey:@"maxs"];

        NSArray * arrays1 = [mincomponentsSeparatedByString:@"/"];

        NSArray *arrays2 = [maxcomponentsSeparatedByString:@"/"];

        NSLog(@"%@",arrays1);

        NSLog(@"%@",arrays2);

        NSMutableArray *a = [[NSMutableArrayalloc]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.viewaddSubview: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,@"/"];

        }

        elseif((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对应的键盘往下收

    

    returnYES;

    

}

//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

0 0
原创粉丝点击