iPhone - 检查每个视图之前是否已加载
我遇到了一个以前没有以这种特殊方式解决过的问题,所以希望有人可以帮助我解决。假设我有一个带有四个视图的选项卡栏应用程序,每个选项卡上一个。显然,应用程序将被迫使用被告知启动的视图控制器启动,但之后,由用户选择接下来加载哪个选项卡(视图)。
问题来自这样一个事实:我只想在第一次加载特定视图时在每个选项卡上显示视图。通常,您会这样做:
BOOL foo = [[NSUserDefaults standardUserDefaults]boolForKey:@"previouslyLaunched"];
if (!foo)
{
NSLog(@"FirstLaunch");
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"previouslyLaunched"];
///Do first run view initializaton here////
}
但是,一旦这样做就会为所有应用程序设置 NSUserDefault ,这意味着只有选项卡 1 的视图才会显示,而不会显示其他三个。所以,我的问题是,如何仅在每个视图第一次加载时显示四个选项卡中每个选项卡的视图?这是一个复杂的问题,因为用户可以以任何顺序选择任何选项卡,所以我认为我无法引导他们走上一条路。
我是否必须为每个视图使用不同的密钥?那行得通吗?看起来这可能是最好的做法,但这是我第一次使用 NSUserDefaults,所以我有点迷失。
非常感谢任何和所有的帮助!
I have a problem that I have not seen addressed in this particular way before, so hopefully someone can help me with it. Let's say I have a tab bar app with four views, one on each tab. Obviously the app will be forced to launch with the view controller it is told to launch with, but after that, it's up to the user to select which tab (view) to load next.
The problem comes from the fact that I would like to show a view on each tab ONLY the first time that particular view is loaded. Normally, you'd do this:
BOOL foo = [[NSUserDefaults standardUserDefaults]boolForKey:@"previouslyLaunched"];
if (!foo)
{
NSLog(@"FirstLaunch");
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"previouslyLaunched"];
///Do first run view initializaton here////
}
However, doing that once sets the NSUserDefault
for all of the app, meaning that only the view for tab 1 will show and not the other three. So, my question is, how do I show a view for each of my four tabs only the first time each view loads? This is a complicated question because the user is able to select any tab in any order, so I can't guide them down a path, I think.
Would I have to use a different key for each view? Would that work? It seems like that might be the best course of action here, but this is my first time working with NSUserDefaults
, so I'm a little lost.
Any and all help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对每个视图使用不同的键:
例如 viewController1PreviouslyLaunched、viewController2PreviouslyLaunched... 等
Use a different key for each view:
e.g. viewController1PreviouslyLaunched, viewController2PreviouslyLaunched... etc