2 fhongchan FHongchan 于 2015.06.06 13:33 提问

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个回答

zhao18933
zhao18933   2015.06.25 11:02
已采纳

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

darongzi1314
darongzi1314   2015.06.08 17:32

你虽然启动了这个viewController,但是你没有加载对应的storyboard,所以当然不会显示 的

u011988082
u011988082   2015.06.09 16:11

没有添加xib,我的博客上有http://blog.csdn.net/u011988082/article/details/46397833

Derek_miss
Derek_miss   2015.06.29 15:50

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

Csdn user default icon
上传中...
上传图片
插入图片