意见重复? - ECSlidingViewController

时间:2013-09-20 00:58:49

标签: ios objective-c uitableview

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

例如,如果我在GudjonDaneil内并打开“抽屉”并再次点击GudjonDaniel,则viewDidLoad方法会调用两次,如果我再次打开它,它会连续3次调用viewDidLoad 。看起来这些观点相互叠加。一旦我再次打开视图,我就需要杀死类(视图)。

点击-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

1 个答案:

答案 0 :(得分: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. 根据您单击的菜单单元格,检查slideViewController是否正常 当前的顶视图与您要的相同......
  5. 如果不相同,请将正确的视图加载到topviewcontroller
  6. 关闭菜单