如何在iPhone的左侧控制器的表格视图行上单击以更改中心视图?(MFSideMenu) [英] How to change centerview on click of tableview row of leftsidecontroller in iphone?(MFSideMenu)
问题描述
am使用 MFSideMenu 为我的iPhone应用程序实施侧边栏.我已经成功实现了侧边栏. 在我的appdelegete中使用以下代码
am using MFSideMenu for my iphone app to implement a side bar. I have successfully implemented the sidebar. with the following code in my 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;
}
现在让我解释一下我的问题.
Now Let me explain my problem..
我有LeftSideViewController的View-controller名称,其中有UITablview 在应用程序启动时,有一个视图控制器作为名为"ViewController"的中心视图 我不需要右侧视图控制器,所以我就包括了
I have View-controller name with LeftSideViewController in which there is UITablview And on application starts there is one view-controller as a center view named as "ViewController" I don't need right-side view controller so i dint include that
现在 我的左侧控制器中有UITableview,单击该UITableview的行后,我必须更改中心视图.
now I have UITableview in my leftsidecontroller and on click of that UITableview's row i have to change the center view.
我的问题是,当我将这段代码放入左侧视图控制器的uitableview delegete方法中时,这不会更改新视图控制器的中心视图
My problem is that when i put this code in my leftside view controller's uitableview delegete method as this its not changing my centerview with new view controller
-(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行单击时相应地更改视图.
Can anyone please give me some guidance that how to change the views accordingly the leftside view's UITableview row click.
推荐答案
我也在使用MFSideMenu.这是我如何处理didSelectRowAtIndexPath ...
I am using MFSideMenu too. Here's how I'm handling the didSelectRowAtIndexPath...
尽管,我在我的情节提要中使用.但是我也像您一样在NavigationControllers中嵌入了视图控制器,并且发现了这种过渡到工作的方法.
Although, I'm using storyboard in mine. But I also have viewcontrollers embedded within NavigationControllers like you do, and I found this method of transitioning to work.
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];
这篇关于如何在iPhone的左侧控制器的表格视图行上单击以更改中心视图?(MFSideMenu)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!