开发者社区> 问答> 正文

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

screenshot
screenshot
screenshot
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;
 }

展开
收起
爵霸 2016-03-13 09:30:47 2847 0
1 条回答
写回答
取消 提交回答
  • 你的ViewController 都重新初始化了,当然就没有了

    2019-07-17 19:01:45
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载