iphone - PushViewController不能与Reveal Controller一起使用

时间:2013-08-03 11:53:32

标签: iphone ios uitableview uinavigationcontroller

我正在创建一个iphone应用程序,其中我在主视图控制器类中有多个网格视图。所以,我想从主视图中选择一个网格单元时,应该加载一个Reveal控制器。布局看起来像

enter image description here enter image description here

我的主视图控制器中有以下代码。

-(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,但没有任何效果。 感谢。

1 个答案:

答案 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;