//
//  IPViewController.m
//  Open
//
//  Created by 黄江涛  on 16/9/8.
//  Copyright © 2016年 黄江涛 . All rights reserved.
//

#import "IPViewController.h"

@interface IPViewController ()<UITextFieldDelegate>
@property(nonatomic,strong)UITextField* IPtext;
@end

@implementation IPViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.modalPresentationStyle=UIModalPresentationPopover;

    self.view.backgroundColor=[UIColor whiteColor];

    
    //输入框
    UITextField* text=[[UITextField alloc]initWithFrame:CGRectMake((self.view.frame.size.width/2)-125, 50, 250, 20)];
    text.placeholder=@"请输入完整的地址";
    text.delegate=self;

    self.IPtext=text;
    [self.view addSubview:text];
    
    //确定按钮
    UIButton* button=[UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    [button setFrame:CGRectMake((self.view.frame.size.width/2)-100, 80, 200, 100)];
    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
   
}
-(void)back{
     NSUserDefaults* userDefault=[NSUserDefaults standardUserDefaults];
    [userDefault setObject:self.IPtext.text forKey:@"Ip"];
    
    [userDefault synchronize];
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    //点击键盘上的return收起键盘
    [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
