我有一個項目與this相同的菜單,但與子菜單相同的幻燈片動畫。我創建了一個名爲SecondMenu.xib的xib文件名。文件所有者是UIViewController並將其命名爲SecondMenuController。如果您檢查項目REFrosted(check the link),則有DEMOMenuViewController(UIViewController)。在方法didSelectRowAtIndexPath:中。我在我的代碼中更改了它NSArrayM replaceObjectAtIndex:withObject:object can not be nil'
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < 1; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
SecondMenuController *controller = [self.viewControllers objectAtIndex:0];
if ((NSNull *)controller == [NSNull null]) {
controller = [[SecondMenuController alloc] initWithNibName:@"SecondMenu" bundle:nil];
[self.viewControllers replaceObjectAtIndex:0 withObject:controller];
}
controller.view.frame = CGRectMake(-self.view.frame.size.width, 0,self.view.frame.size.width,self.view.frame.size.height);
[self.view addSubview:controller.view];
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
controller.view.frame = CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height);
} completion:^(BOOL finished) {
NSLog(@"Done!");
}];
//[self hideMenu];
}
當連接到子菜單(即SecondMenuController)時,該代碼適用於我。在我的SecondMenuController中,我添加一個按鈕(這將連接到DEMOHomeViewController,故事板標識符是homeController)。這裏是我的按鈕
- (IBAction)buttonConnect:(id)sender {
DEMONavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentController"];
DEMOHomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"homeController"];
navigationController.viewControllers = @[homeViewController];
self.frostedViewController.contentViewController = navigationController;
[self.frostedViewController hideMenuViewController];
}
的代碼,我得到這個代碼REFrosted之前,我把它改爲我的代碼在didSelectRowAtIndexPath方法:(正如我在第一個代碼提到上文)。爲什麼我得到這個錯誤
'NSInvalidArgumentException', reason: '*** -[__NSArrayM replaceObjectAtIndex:withObject:]: object cannot be nil'
我導入所有文件。正如我所瞭解的,當你導入連接到文件所有者的文件時。這意味着我可以控制每個方法或函數,當你將它實例化到我的SecondMenuController時(這只是基於我的經驗,如果我錯了,請糾正我,我只想知道系統是如何工作的)。請參閱我的代碼。我在這裏錯過了什麼嗎?希望你建議我如何解決這個問題或解釋爲什麼我得到這個錯誤。
DEMONavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentController"];
DEMOHomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"homeController"];
navigationController.viewControllers = @[homeViewController];
你對錯誤信息有什麼不瞭解?它說'控制器'是零,你是否證實它不是零?例如'NSLog()'?你需要調試你的代碼。 – zaph 2014-11-24 02:36:59
是的,homeViewController是零。爲什麼是零?該班級已經連接到該董事會。 – user3818576 2014-11-24 02:42:35
調試時間。仔細檢查所有內容,拼寫錯誤,類名等。重新閱讀文檔。 – zaph 2014-11-24 03:11:35