我可以在viewDidLoad..中调用presentModalViewController吗?
在我的 iPhone 应用程序中,我有 HomeViewController 和 ContentViewController。我使用 NSUserDefaults 保存 ContentViewController 中的值 并根据保存的值,当应用程序重新启动时,我将加载 ContentView 而不是 HomeView。如果 NSUserDefaults 中没有值,则显示 HomeView。
在 HomeView 中我有一些按钮..就像这样..每个按钮都用于一本书,因此在 contentView 中,如果我单击某个页面,则将显示所有页面编号(在 ContentView 的滚动视图的底部),不会显示ContentView 上面标签中的文本。如果用户在 contentView 中关闭应用程序,则页面号和书号将被保存...如果用户单击主页按钮,所有信息将被删除。 在主页视图中,我检查 NSUserDefaults,如果它包含值,它应该显示该书的确切页面 以下是代码...
//HomeViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
contentViewController = [[ContentViewController alloc] initWithNibName:@"ContentView" bundle:nil];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSLog(@"...%d,%d,%d",[prefs integerForKey:@"Stage"],[prefs integerForKey:@"Stimulus"],[prefs integerForKey:@"Card"]);
if(!([prefs integerForKey:@"Stage"] ==0 && [prefs integerForKey:@"Stimulus"] ==0 && [prefs integerForKey:@"Card"] ==0)){
[contentViewController setCurrentState:[prefs integerForKey:@"Stage"]];
[contentViewController setCurrentStimulus:[prefs integerForKey:@"Stimulus"]];
[contentViewController setCurrentCard:[prefs integerForKey:@"Card"]];
[self presentModalViewController:contentViewController animated:YES];
}
}
但它显示的是主页视图。
In my iPhone app I have HomeViewController and ContentViewController. I am saving the values in ContentViewController by using NSUserDefaults
and based on saved values I will load the ContentView instead of HomeView when the app is restarted. if there r no values in the NSUserDefaults it displays the HomeView.
in HomeView I have some buttons..it's like this.. each button is for a book so in contentView all the page nos (in the bottom in a scroll view in ContentView) will be displayed if I click on a page no it displays the text in the above label of ContentView.if the user closes the app in contentView, the page no and book no will be saved...if the user clicks on home button all the information will be deleted.
In the Homeview im checking the NSUserDefaults, if it contains values it should display that exact page of that book
the following is the code...
//HomeViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
contentViewController = [[ContentViewController alloc] initWithNibName:@"ContentView" bundle:nil];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSLog(@"...%d,%d,%d",[prefs integerForKey:@"Stage"],[prefs integerForKey:@"Stimulus"],[prefs integerForKey:@"Card"]);
if(!([prefs integerForKey:@"Stage"] ==0 && [prefs integerForKey:@"Stimulus"] ==0 && [prefs integerForKey:@"Card"] ==0)){
[contentViewController setCurrentState:[prefs integerForKey:@"Stage"]];
[contentViewController setCurrentStimulus:[prefs integerForKey:@"Stimulus"]];
[contentViewController setCurrentCard:[prefs integerForKey:@"Card"]];
[self presentModalViewController:contentViewController animated:YES];
}
}
but it's displaying the homeview.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用下面所示的方法viewDidAppear而不是viewDidLoad
Try using the method viewDidAppear shown below instead of viewDidLoad