當我的應用程序啓動時,當設置首選項指示用戶未接受使用條款時,我正在嘗試顯示服務條款模式視圖。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
沒錯。細節一如既往依賴於你需要做的事情。 –