从侧栏菜单推送到ios中的另一个视图控制器

时间:2013-06-22 13:01:34

标签: iphone ios storyboard sidebar uistoryboardsegue

我在我的应用程序中使用,像在facebook中的侧栏菜单,所以我在这个菜单中有不同的单元格,我想要的是当单击一个单元格时将我推送到另一个视图控制器。我在这里遇到一个问题:菜单是一个表格视图,我在故事板中没有它,我使用this site:github中的一些类

我已经坚持到这里,在我的应用程序中我使用了故事板,但是这个菜单是用代码编程的,并且在stroyboard中没有视图,

在didSelectRowAtIndexPath方法中:我像这样使用

    for(int j=0; j< 9 ; j++)
    {
               if(indexPath.row == j)
               {
                     DetailsSidebarViewController *essayView = [[DetailsSidebarViewController alloc]  init];
               essayView.detailItem = [jsonResults objectAtIndex:j];
        NSLog(@"%@=%d",essayView.detailItem,j);
               }
     }

当我从菜单项推送时,我创建了一个DetailsS​​idebarViewController作为新的视图控制器。在这个类中,我创建了一个配置视图的方法,我只是回显结果:

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {

        NSLog(@" %@ ", self.detailItem);


    }
}

结果是我想要的,但是我想推送到另一个视图控制器,实际上当我点击菜单中的项目时没有发生任何事情。

如何在故事板中创建新的视图控制器?如果菜单没有故事板,我怎样才能将它们与segue连接?

事实上,我是蓝色的,请帮助!!

1 个答案:

答案 0 :(得分:0)

您应该在Side Menu视图控制器中创建App Delegate类的实例,然后从那里推送它。您必须引用侧面菜单视图和对中心视图的引用!将App Delegate导入Side Menu控制器,并在didSelectRowAtIndexPath中使用:

 DetailsSidebarViewController *essayView = [[DetailsSidebarViewController alloc]  init];
 essayView.detailItem = [jsonResults objectAtIndex:indexPath.row]; // note that you don't need the for loop to know what object you need
 AppDelegate* myAppDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
 [myAppDelegate.sideMenuViewController toggleSideMenu]; // the idea here is that you have to close the side menu, i.e. it must dissapear
 [myAppDelegate.centerViewController.navigationController pushViewController:essayView animated:YES];

这是您需要的所有代码。 如果我可以作为一条建议使用Mike Frederik's MFSideMenu而不是您正在使用的库。在我看来,它有一个更简单,更直接的实现,只需查看README文件,一切都解释得非常简单,它具有您需要的代码! 希望这有帮助,祝你好运!