2013-06-27 47 views
1

我有一個名爲CKCalendarViewControllerInternal的自定義視圖控制器。在iOS中初始化視圖控制器sdk

CKCalendarViewControllerInternal

這個類的UIViewController的子類。

CkCalendarViewController

我有一個名爲CKCalendarViewController自定義視圖控制器。它的UINavigationController一個子類如下:

@interface CKCalendarViewController : UINavigationController <CKCalendarViewDelegate, UINavigationControllerDelegate> 

這個類是與CKCalendarViewControllerInternal如下初始化:

- (id)init 
{ 
    CKCalendarViewControllerInternal *calendarViewController = [CKCalendarViewControllerInternal new]; 

    self = [super initWithRootViewController:calendarViewController]; 
} 

現在,在AppDelegate我的第一個觀點是如下:

AppDelegate中。 m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 

    UINavigationController *n1=[[UINavigationController alloc]init]; 
    n1.viewControllers=[[NSArray alloc]initWithObjects:self.viewController, nil]; 

self.window.rootViewController=n1; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

CkDemoViewController

這個類是CkCalendarViewController子類如下

@interface CKDemoViewController : CKCalendarViewController 

ViewController.m

當我嘗試推CKDemoViewController按鈕點擊。

錯誤&問題 這說明我的錯誤一樣

Exception: Pushing a navigation controller is not supported Exception: [NSException]:Pushing a navigation controller is not supported ex.name:'NSInvalidArgumentException' ex.reason:'Pushing a navigation controller is not supported'

錯誤原因 這是因爲CKCalendarViewControllerUINavigationController的子類。 如果我嘗試打開模式視圖,它完美的作品。

但是我怎樣才能初始化CKCalendarViewController如上所示與CKCalendarViewControllerInternal類?

謝謝

答案,將會極大地

+0

爲什麼自定義視圖控制器分類爲'UINavigationController'? –

+0

爲什麼你不在'[[CKCalendarViewController alloc] init]'? – Wain

+0

@ LithuT.V,謝謝你的回覆。但這是日曆演示,我從可可控制這個項目。我不太瞭解這個。鏈接:[https://www.cocoacontrols.com/controls/mbcalendarkit] – user2526811

回答

2

如果我理解你在做正確的東西,最簡單的「的hackish」的方式,使事情的工作將作出CKCalendarViewControllerCKCalendarViewControllerInternal派生。我建議這樣做是因爲我看到你正在嘗試使用你的CKCalendarViewController作爲一個普通的視圖控制器,所以應該沒有理由讓它成爲一個導航控制器。

另一種可能性將是你真正在你的應用程序代理這樣使用CKCalendarViewController作爲導航控制器:

UINavigationController *n1 = [[CKCalendarViewController alloc]init]; 
n1.viewControllers = [[NSArray alloc]initWithObjects:self.viewController, nil]; 
self.window.rootViewController = n1; 

但是這取決於你想要達到的目的。更一般地,如果您對控制器內的「嵌套」控制器感興趣,您應該瞭解controller containment。在控制器遏制中,你做什麼來添加控制器到另一個基本上是這樣的:

[vc willMoveToParentViewController:self]; 
[self addChildViewController:vc]; 
[self.view addSubview:vc.view]; 
[vc didMoveToParentViewController:self]; 
+0

偉大的編碼!感謝您的回覆... – user2526811

相關問題