0

我目前正在使用该ECSlidingViewController示例,并且在打开我当前所在的同一视图时遇到了一个小错误。

例如,如果我在里面GudjonDaneil,我打开“抽屉”并GudjonDaniel再次点击 viewDidLoad 方法调用两次,如果我再次打开它,它会连续调用 viewDidLoad 3 次。看起来视图是相互堆叠的。一旦我再次打开视图,我需要以某种方式杀死类(视图)。

这是单击后会发生的情况-UItableView

 NSLog(@"Channel 1 Loading");
        tableViewCellLoading = true;
        [self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
            CGRect frame = self.slidingViewController.topViewController.view.frame;
            self.slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"firstChannel"];
            self.slidingViewController.topViewController.view.frame = frame;
            [self.slidingViewController resetTopView];
            [tableView deselectRowAtIndexPath:indexPath animated:YES]; }];

抽屉应用程序的外观

http://gyazo.com/f811283fadbad5b50ee4d594b6798f18

4

1 回答 1

0

我知道这个问题被问到已经有一段时间了……但是对于其他正在寻找的人来说,这是一个答案。

以下来自我的“MenuController.m”文件。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    self.slidingViewController.topViewController.view.layer.transform = CATransform3DMakeScale(1, 1, 1);
    UINavigationController *currentNav = (UINavigationController *)self.slidingViewController.topViewController;
    UIViewController *theControllerYouWant = [currentNav.viewControllers objectAtIndex:([currentNav.viewControllers count]-1)];
    NSString *CurrentSelectedCViewController = NSStringFromClass(theControllerYouWant.class);

    if (indexPath.row == 1 && ![CurrentSelectedCViewController isEqualToString:@"PeopleTableViewController"]) {
        [(UINavigationController *)self.slidingViewController.topViewController setViewControllers: [NSArray arrayWithObject: [self.storyboard instantiateViewControllerWithIdentifier:@"PeopleView"]]];
    } else if (indexPath.row == 2 && ![CurrentSelectedCViewController isEqualToString:@"CompanyPickerController"]) {
        [(UINavigationController *)self.slidingViewController.topViewController setViewControllers: [NSArray arrayWithObject: [self.storyboard instantiateViewControllerWithIdentifier:@"CompanyView"]]];
    }
    [self.slidingViewController resetTopViewAnimated:YES];
}

基本解释是这样的:

  1. 获取对当前导航控制器的引用
  2. 获取导航控制器顶部视图的引用(始终是其数组中的最后一个视图)
  3. 获取该视图的字符串表示形式。
  4. 根据您单击的菜单单元格,检查slidingViewController 的当前顶视图是否与您要访问的相同。
  5. 如果不一样,将正确的视图加载到 topviewcontroller
  6. 关闭菜单
于 2014-07-28T07:48:57.310 回答