fhongchan 2015-06-06 05:33 采纳率: 73.3%
浏览 4618
已采纳

iOS在故事板中画好界面 在APPDelegate里面设置启动这个页面的时候 看不见控件

图片说明
图片说明
图片说明

AppDelegate 代码

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    ViewController *vc = [ViewController new];
    vc.dictUserInfo=@{@"User":[[NSUserDefaults standardUserDefaults] objectForKey:@"User"],
    @"Pwd" : [[NSUserDefaults standardUserDefaults] objectForKey:@"Pwd"],
    @"IP" : [[NSUserDefaults standardUserDefaults] objectForKey:@"IP"]
    };
    self.window.rootViewController = vc;
    return YES;
    }

ViewController.m 代码

  • (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor whiteColor]; self.alertView = [[UIAlertView alloc]initWithTitle:@"失败" message:@"你好" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [self.view addSubview:self.alertView]; self.txtIP.delegate = self; self.txtUser.delegate = self; self.txtPwd.delegate =self; }

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.txtUser.text =self.dictUserInfo[@"User"];
self.txtPwd.text = self.dictUserInfo[@"Pwd"];
self.txtIP.text = self.dictUserInfo[@"IP"];
}

  • (IBAction)btnLoginClick:(id)sender {
    NSString *user =self.txtUser.text;
    NSString *pwd = self.txtPwd.text;
    NSString *address = self.txtIP.text;

    if (user.length>0&&pwd.length>0&&address.length>0) {
        [[NSUserDefaults standardUserDefaults] setObject:user forKey:@"User"];
        [[NSUserDefaults standardUserDefaults] setObject:pwd forKey:@"Pwd"];
        [[NSUserDefaults standardUserDefaults] setObject:address forKey:@"IP"];
    }
    else
    {
        self.alertView.message=@"参数输入错误!";
        [self.alertView show];
    }
    

    }

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

  • 写回答

4条回答 默认 最新

  • sun_ljz 2015-06-25 03:02
    关注

    你的ViewController 都重新初始化了,当然就没有了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 HC32L176调试了一个通过TIMER5+DMA驱动WS2812B
  • ¥15 三菱FX系列PLC串口指令
  • ¥15 cocos的js代码调用wx.createUseInfoButton问题!
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!
  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥35 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 Todesk 远程写代码 anaconda jupyter python3