我正在创建一个iphone应用程序,其中我在主视图控制器类中有多个网格视图。所以,我想从主视图中选择一个网格单元时,应该加载一个Reveal控制器。布局看起来像
我的主视图控制器中有以下代码。
-(void) gridView:(UzysGridView *)gridView didSelectCell:(UzysGridViewCell *)cell
atIndex:(NSUInteger)index
{
if (index == 0){
FrontViewController *frontViewController = [[FrontViewController alloc]
init];
RightViewController *rightViewController = [[RightViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc]
initWithRootViewController:frontViewController];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:nil
frontViewController:frontNavigationController];
mainRevealController.delegate = self;
self.revealController.rightViewController = rightViewController;
self.revealController = mainRevealController;
[self.navigationController pushViewController:self.revealController animated:YES];
}
这里是主视图控制器.h文件,
@property (strong, nonatomic) SWRevealViewController *revealController;
我也声明了SWRevealViewControllerDelegate。问题是这个self.revealController没有加载/显示。我也尝试过App Delegate,但没有任何效果。 感谢。
答案 0 :(得分:2)
我解决了它:使用下面的代码..
-(void) gridView:(UzysGridView *)gridView didSelectCell:(UzysGridViewCell *)cell
atIndex:(NSUInteger)index {
if (index == 0){
FrontViewController *frontViewController = [[FrontViewController alloc]
init];
myNavigationController = [[UINavigationController alloc]
initWithRootViewController:frontViewController];
SWRevealViewController *revealController = [[SWRevealViewController alloc]
initWithRearViewController:nil frontViewController:myNavigationController];
revealController.delegate = self;
RightViewController *rightViewController =
[[RightViewController alloc] init];
rightViewController.view.backgroundColor = [UIColor greenColor];
revealController.rightViewController = rightViewController;
self.viewController1=revealController;
[self presentViewController:self.viewController1 animated:YES completion:nil];
}
}
在Class.h文件中
@property(nonatomic, strong) UINavigationController *myNavigationController;
@property(nonatomic, strong) SWRevealViewController *viewController1;