gpt4 book ai didi

iphone - 如何在 iphone 中单击左侧 Controller 的 TableView 行更改中心 View ?(MFSideMenu)

转载 作者:行者123 更新时间:2023-11-28 19:09:25 29 4
gpt4 key购买 nike

我正在使用 MFSideMenu 让我的 iPhone 应用程序实现侧边栏。我已经成功地实现了侧边栏。在我的 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 名称为 LeftSideViewController,其中有 UITablview在应用程序启动时,有一个 View Controller 作为中心 View ,名为“ViewController”我不需要右侧 View Controller ,所以我力图包含它

现在我的 leftsidecontroller 中有 UITableview,单击该 UITableview 的行我必须更改中心 View 。

我的问题是,当我将此代码放入左侧 View Controller 的 uitableview delegete 方法时,因为它不会用新的 View Controller 更改我的中心 View

-(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];

}

任何人都可以给我一些指导,如何根据左侧 View 的 UITableview 行点击更改 View 。

最佳答案

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

虽然,我在我的 Storyboard中使用。但我也像您一样在 NavigationController 中嵌入了 View Controller ,我发现这种转换方法很有效。

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 - 如何在 iphone 中单击左侧 Controller 的 TableView 行更改中心 View ?(MFSideMenu),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17102600/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com