ios - 从每个单元格命名并执行操作

时间:2014-05-16 15:19:04

标签: ios uitableview uiview uiviewcontroller

所以我使用这段代码......" MFSideMenuDemoStoryboard" https://github.com/mikefrederick/MFSideMenu/tree/master/Demos/MFSideMenuDemoStoryboard/MFSideMenuDemoStoryboard

我想给" SideMenuViewController.m"中的每个单元格命名。并使这些单元格中的每一个在" DemoViewController.m"中显示特定的UIView。对此有何帮助?

感谢任何帮助,谢谢!!

1 个答案:

答案 0 :(得分:0)

SideMenuController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DemoViewController *demoController = [[DemoViewController alloc] initWithNibName:@"DemoViewController" bundle:nil];
    demoController.title = [NSString stringWithFormat:@"Demo #%d-%d", indexPath.section, indexPath.row];

    UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
    NSArray *controllers = [NSArray arrayWithObject:demoController];
    navigationController.viewControllers = controllers;
    [self.menuContainerViewController setMenuState:MFSideMenuStateClosed];

}

将此代码替换为:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   //EDIT #1
    UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
    DemoViewController *currentCenterView = [[navigationController viewControllers] firstObject];
    [currentCenterView addAnotherView:indexPath.row]; //This is where you will tell your 'middle view' to load another UIView ... You can use the indexPath.row to determine which option was tapped and act accordingly.

    [self.menuContainerViewController setMenuState:MFSideMenuStateClosed];

}

您显然需要向- (void) addAnotherView:(NSInteger ) row;或您调用的任何方法添加方法DemoViewController

编辑#1这将引用当前加载的视图。这仅在您在导航控制器堆栈上使用1个视图控制器时才有效。否则,抓取第一个对象将无法工作,您需要搜索正确的索引。