0

我正在为我的 iphone 应用程序使用MFSideMenu 来实现侧边栏。我已经成功实现了侧边栏。在我的 appdelegete 中使用以下代码

- (ViewController *)demoController {
    return [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}

- (UINavigationController *)navigationController {
    return [[UINavigationController alloc]
            initWithRootViewController:[self demoController]];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        LeftSlideViewController *leftMenuViewController = [[LeftSlideViewController alloc] init];


        MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
                                                        containerWithCenterViewController:[self navigationController]
                                                        leftMenuViewController:leftMenuViewController
                                                        rightMenuViewController:nil];


        container.navigationController.navigationItem.rightBarButtonItem=nil;
        self.window.rootViewController = container;
        [self.window makeKeyAndVisible];

        return YES;
}

现在让我解释我的问题..

我有 View-controller name with LeftSideViewController 其中有 UITablview 并且在应用程序启动时有一个 view-controller 作为名为“ViewController”的中心视图我不需要右侧视图控制器所以我力求包括

现在我的左侧控制器中有 UITableview 并且单击该 UITableview 的行我必须更改中心视图。

我的问题是,当我将此代码放在左侧视图控制器的 uitableview 委托方法中时,它不会用新的视图控制器更改我的中心视图

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      // Load new front view
          MFSideMenuContainerViewController *menuController = (MFSideMenuContainerViewController*)((AppDelegate*)[[UIApplication sharedApplication] delegate]).viewController;

        PhotoGalleryViewController *SearchBarTableView=[[PhotoGalleryViewController alloc]initWithNibName:@"PhotoGalleryViewController" bundle:nil];
        [self.navigationController pushViewController:SearchBarTableView animated:YES];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:SearchBarTableView];
        menuController.centerViewController=navController;
        //[menuController1 setRootController:navController animated:YES];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

谁能给我一些指导,告诉我如何相应地更改视图左侧视图的 UITableview 行单击。

4

2 回答 2

3

我也在使用 MFSideMenu。这是我处理 didSelectRowAtIndexPath 的方式...

虽然,我在我的中使用故事板。但是我也像您一样在 NavigationControllers 中嵌入了视图控制器,并且我发现了这种过渡到工作的方法。

if (indexPath.section ==1 ){
    if (indexPath.row==0){
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
        UITabBarController *destNav = [storyboard instantiateViewControllerWithIdentifier:@"MainTabBar"];
        [self.menuContainerViewController setCenterViewController:destNav];
    }
    if (indexPath.row==1){
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
        UINavigationController *destNav = [storyboard instantiateViewControllerWithIdentifier:@"TopNavID"];
        [self.menuContainerViewController setCenterViewController:destNav];
    }
    if (indexPath.row == 2){

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
        UINavigationController *destNav = [storyboard instantiateViewControllerWithIdentifier:@"OptionsNavID"];
        [self.menuContainerViewController setCenterViewController:destNav];

    }
}


[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
于 2013-09-26T20:07:46.957 回答
1

你应该从你的 centerview 和 LeftSideViewController 实现委托方法。所以真正改变视图的是你的中心视图的方法。我的 didSelectRowAtIndexPath 中的代码:

else if (indexPath.section==1 && indexPath.row==0) {
    [delegate chooseCategory:2];

}
else if (indexPath.section==1 && indexPath.row==1) {
    [delegate chooseCategory:3];

}
else if (indexPath.section==1 && indexPath.row==2) {
    [delegate chooseCategory:15];

}

chooseCategory 是 centerview 中用于更改其视图的方法。

于 2013-07-09T05:21:35.547 回答