NSuserdefaults 未在选项卡栏控制器中加载,适用于 uiview
我在让 NSUserDefaults 在选项卡/导航/tableview 控制器页面上拉出时遇到问题,我已将相同的代码放在登录页面上,应用程序将完美地拉出键的对象。当我以编程方式创建选项卡和导航时,我可以使用此功能,但现在它不起作用。 loginViewController 不在选项卡堆栈中,这是它工作的原因吗?
-(void)refreshFields {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
usernameLabel.text = [defaults objectForKey:kUsernameKey];
passwordLabel.text = [defaults objectForKey:kPasswordKey];
}
- (void)viewDidAppear:(BOOL)animated {
[self refreshFields];
[super viewDidAppear:animated];
if ([usernameLabel.text length] == 0|| [passwordLabel.text length] == 0)
{
UINavigationController *loginNavigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[loginViewController release];
[self.navigationController presentModalViewController:loginNavigationController animated:NO];
[loginNavigationController release];
}
else
{
[[self tableView ]reloadData];
}
}
I have a problem getting the NSUserDefaults to pull out on a tab/nav/tableview controller page, I've put the same code on a loginpage and the app will pull the objects for keys perfectly. I had this working when I had programmatically created the tabs and navs but now it's not working. The loginViewController is not in the tab stack, is that the reason it works?
-(void)refreshFields {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
usernameLabel.text = [defaults objectForKey:kUsernameKey];
passwordLabel.text = [defaults objectForKey:kPasswordKey];
}
- (void)viewDidAppear:(BOOL)animated {
[self refreshFields];
[super viewDidAppear:animated];
if ([usernameLabel.text length] == 0|| [passwordLabel.text length] == 0)
{
UINavigationController *loginNavigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[loginViewController release];
[self.navigationController presentModalViewController:loginNavigationController animated:NO];
[loginNavigationController release];
}
else
{
[[self tableView ]reloadData];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 usernameLabel 和 passwordLabel 出口未设置。通过在刷新字段中放置断点进行验证。
Your usernameLabel and passwordLabel outlets aren't set. Verify by putting a breakpoint in refreshFields.