当我的应用程序启动时,当设置首选项指示用户未接受使用条款时,我正在尝试显示服务条款模式视图。appDelegate可以成为模态视图的代表吗?
所以在我的ApplicationDidFinishLaunchingWithOptions的appDelegate,我有这样的代码:
if (TOSAcceptedPrefValue) { //has not been accepted
// Create the root view controller for the navigation controller
TermsOfServiceController *termsOfServiceController = [[TermsOfServiceController alloc]
initWithNibName:@"TermsOfServiceController" bundle:nil];
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:termsOfServiceController];
termsOfServiceController.delegate = self;
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[TermsOfServiceController release];
NSLog(@"1");
}
然而,Xcode是表明termsOfServiceController.delegate =自被“分配给来自不亲型'身份证‘MyAppAppDelegate *’” 。
我觉得我完全实现我的AppDelegate头模态协议:
@protocol TOSModalViewDelegate
- (void)didAcceptTermsOfService:(NSString *)message;
- (void)didRejectTermsOfService:(NSString *)message;
@end
@interface MyAppAppDelegate : NSObject <UIApplicationDelegate, TOSModalViewDelegate> ...
,并在modalview头:
@protocol ModalViewDelegate ;
@interface TermsOfServiceController : UIViewController {
id<ModalViewDelegate> delegate; ...
...
@property (nonatomic, assign) id<ModalViewDelegate> delegate;
,我合成它在modalview实行文件。
根据这个example,我将AppDelegate.m文件中的代码移动到窗口实例化后,但仍然有来自Xcode的警告。
警告会导致应用程序崩溃与此错误:
2011-09-05 08:34:12.237 MyApp[4416:207] TOSAcceptedPrefValue = 0 2011-09-05 08:34:13.732 MyApp[4416:207] displayWelcomeScreenPrefValue = 0 2011-09-05 08:34:42.889 MyApp[4416:207] -[MyAppAppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance 0x552b430 2011-09-05 08:34:42.892 MyApp[4416:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyAppAppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance 0x552b430'
所以我的问题是,是否可以从AppDelegate中显示模式的看法,如果是这样,我应该怎么改变,使之发生。
感谢您的帮助
好的,这很酷。感谢您的解释!所以你说,我的普通第一个视图控制器(一个配置文件视图)通过AppDelegate显示,但立即,配置文件视图控制器将检查它的viewdidload,看看是否需要显示服务条款? – Jazzmine
没错。细节一如既往依赖于你需要做的事情。 –