我在玩很棒的库ZUUIRevealController。但是,我无法对其进行编程,因此用户可以在后控制器中点击一个单元。然后,后控制器应该消失,并在前视图中显示一个新的视图控制器。
我已经像这样设置了我的项目:
VGViewController *frontViewController;
RevealController *rearViewController;
frontViewController = [[VGViewController alloc] initWithNibName:@"VGViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
rearViewController = [[RevealController alloc] initWithNibName:@"RevealController" bundle:nil];
ZUUIRevealController *revealController = [[ZUUIRevealController alloc] initWithFrontViewController:self.navigationController rearViewController:rearViewController];
[frontViewController release];
[rearViewController release];
self.window.rootViewController = revealController;
[revealController release];
[self.window makeKeyAndVisible];
return YES;
我希望有一个人可以帮助我! :D
最佳答案
很高兴您在图书馆发现喜欢的东西。
如果我不丢失任何内容,则您的项目似乎已正确设置,尽管从逻辑上讲,我无法遵循RearViewController RevealController的方式,但这没关系。
要回答您的问题:
为了显示不同的frontViewController,例如,敲击RearViewController中的单元格,您需要以适当的方法来触发这段代码(例如:tableView:didSelelctRowAtIndexPath :)
// RearViewController.m file in some method:
// - Let's grab a reference to the revealController first:
ZUUIRevealController *revealController = [self.parentViewController isKindOfClass:[ZUUIRevealController class]] ? (ZUUIRevealController *)self.parentViewController : nil;
// Check if we're not attempting to swap the current FrontViewController for exactly the same controller over again...
if (![revealController.frontViewController isKindOfClass:[NewFrontViewController class]])
{
NewFrontViewController *newFrontViewController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
newFrontViewController = [[NewFrontViewController alloc] initWithNibName:@"NewFrontViewController_iPhone" bundle:nil];
}
else
{
newFrontViewController = [[NewFrontViewController alloc] initWithNibName:@"NewFrontViewController_iPad" bundle:nil];
}
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:newFrontViewController];
[newFrontViewController release];
[revealController setFrontViewController:navigationController animated:NO];
[navigationController release];
}
这段代码的作用是,它获取对RearViewControllers父对象(应该是RevealController)的引用,并通过调用
[revealController setFrontViewController:navigationController animated:NO];
为其分配一个新的frontViewController实例。希望这能解决您的问题:-)