【发布时间】:2014-11-24 02:16:33
【问题描述】:
我有一个项目与this 相同的菜单,但子菜单具有相同的幻灯片动画。我创建了一个 xib 文件,将其命名为 SecondMenu.xib。文件所有者是 UIViewController 并将其命名为 SecondMenuController。如果您检查项目REFrosted(check the link),则有DEMOMenuViewController(UIViewController)。在方法 didSelectRowAtIndexPath:.我在我的代码中更改了它
- (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];
}
在将其更改为 didSelectRowAtIndexPath 中的代码之前,我在 REFrosted 中获得了此代码:(正如我在上面第一个代码中提到的那样)。为什么会出现这个错误
'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];
【问题讨论】:
-
您对错误信息有什么不明白的地方?它说
controller是 nil,你确认它不是 nil 吗?NSLog()例如?你需要调试你的代码。 -
是的 homeViewController 为零。为什么是零?该类已连接到板。
-
调试时间。仔细检查所有内容,拼写错误,类名等。重新阅读文档。
标签: ios objective-c xcode5