如何在ios中使用SWRevealViewcontroller导航到sw_front视图?

时间:2015-01-27 14:18:40

标签: ios objective-c swrevealviewcontroller

我正在使用SWRevealViewController来修改我的ios应用程序中的侧边栏。我已经按照appcoda教程来实现它。根据本教程,我已经制作了两个用于主视图控制器(rootviewcontroller)的segue< s sw_front第二个是sw_rear,用于侧边栏。我使用本教程成功地实现了它,但是现在我在从sw_rear视图导航到sw_front segue时遇到问题。请帮助我,如果有人知道这种问题的话。

1 个答案:

答案 0 :(得分:1)

这是我的slidemenu.m

您只需创建菜单项目表,每个项目都有标识符

在每个项目中单击右键,选择显示视图控制器

这一切都是 enter image description here

    #import "SlideMenu.h"
    #import "SWRevealViewController.h"
    @interface SlideMenu ()

    @end

    @implementation SlideMenu{
        NSArray *menu_items;
        NSArray*thumbies;
        NSArray*indentifer;
    }


    - (id)initWithStyle:(UITableViewStyle)style
    {
        self = [super initWithStyle:style];
        if (self) {
            // Custom initialization
        }
        return self;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        indentifer = @[@"report_view" ,@"ann_view" , @"message_view" , @"calendar_view" , @"schedule_view" , @"about_view" , @"student_view" ];

        menu_items = @[@"Reports" , @"Messages" , @"Announcement" , @"Calendar" ,@"Schedule" ,@"About us",@"back to Students"];

        thumbies = @[@"report.png" , @"message.jpg" ,@"ann.jpg", @"calendar.jpg" , @"schedule.png" , @"about.png" ];

    }



    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    #pragma mark - Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {

        // Return the number of sections.
        return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {

        // Return the number of rows in the section.
        return [menu_items count];
    }


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString * cell_identifer = [indentifer objectAtIndex:indexPath.row];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_identifer forIndexPath:indexPath];

        if (cell== nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_identifer];
        }

        //cell.textLabel.text = [menu_items objectAtIndex:indexPath.row];
        //cell.imageView.image = [UIImage imageNamed:[thumbies objectAtIndex:indexPath.row] ];

        return cell;
    }





    #pragma mark - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue isKindOfClass:[SWRevealViewControllerSegue class]]) {
            SWRevealViewControllerSegue *swsegue = (SWRevealViewControllerSegue*)segue;

            swsegue.performBlock = ^(SWRevealViewControllerSegue *rvc_segue , UIViewController * svc , UIViewController *dvc){
                UINavigationController *navController = (UINavigationController *)self.revealViewController.frontViewController;
                [navController setViewControllers:@[dvc] animated:NO];
                [self.revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];
            };

        }
    }


    @end

更新XCODE 6.4的答案

完整示例

创建viewController以保存SWRevealViewController

此视图有后面(幻灯片菜单项),前面(已实现项目) 请检查屏幕截图

enter image description here

enter image description here

从幻灯片菜单viewController类到每个项目

这个表视图实现我的幻灯片菜单项,我使用push方法

(SWRevealViewControllerSeguePushController)

enter image description here

这是导航控制器之前的连接检查器

enter image description here

希望这能满足您的所有需求