【发布时间】:2014-05-02 22:19:38
【问题描述】:
我需要以下代码的帮助。我的目标是显示 UIViewController “条款”(已经存在于我的 Storyboard 中,并且我已经在 Storyboard ID 中指定了名称术语)。如果应用程序已经打开并且用户接受了 T&C,则显示正常的 UIViewController。
FIRSTVIEWCONTROLLER.H
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
@end
@interface First : UIViewController
@end
@interface Terms: UIViewController
@end
FIRSTVIEWCONTROLLER.M
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad: (BOOL)animated
{
[super viewDidLoad];
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];
if (!isAccepted) {
[self presentViewController:Terms animated:YES completion:nil];
} else {
[self.navigationController pushViewController:First animated:YES];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
事实上,我收到 2 个错误:“意外的接口名称 'Terms'/'First': 预期的表达式”。
请看故事板:http://i.stack.imgur.com/bi6aT.png
请帮帮我。 xcode初学者。
【问题讨论】:
-
您在哪里看到错误?指出给您带来问题的确切代码。
-
您的故事板看起来很奇怪,因为您没有指向条款的箭头,而您有很多指向标签栏控制器的箭头。这一切似乎都颠倒了(但我不知道它打算做什么)。如果一个 XCode/storyboards 的初学者从一个视图控制器开始,运行它,然后添加另一个并再次运行,然后添加另一个并再次运行等等。慢慢地构建它
-
@rmaddy 错误出现在
[self presentViewController:Terms animated:YES completion:nil];和[self.navigationController pushViewController:First animated:YES];谢谢。 -
您正在尝试传递类的名称,而不是创建视图控制器的实例。
标签: ios objective-c uiviewcontroller