0

嗨,我从这段代码中收到以下错误:

EXC_BAD_ACCESS (code=2, address=0x3)

当我按下播放时,我基本上是循环回 CFRetain。

我无法弄清楚这有什么问题。

XCode 专门指向这一行:

[NSDictionary dictionaryWithObjectsAndKeys:[self getCorrectName:oldController], @"ViewController", sec, @"duration", nil];

我检查了字典的两个值,它们似乎都检查出来了。

在此处输入图像描述

- (NSString *)getCorrectName:(UIViewController *)viewController {
    if (viewController.class == [UINavigationController class]) {
        UIViewController *vc = [viewController.childViewControllers objectAtIndex:0];
        return NSStringFromClass(vc.class);
    } else {
        return NSStringFromClass(viewController.class);
    }
}

# pragma mark - UITabBarControllerDelegate

- (BOOL)tabBarController:(UITabBarController *)tbController shouldSelectViewController:(UIViewController *)viewController {
    // Tracking which controller will be clicked
    [[Mixpanel sharedInstance] track:@"tab_clicked"
                          properties:[NSDictionary dictionaryWithObjectsAndKeys:
                                      [self getCorrectName:viewController], @"ViewController", nil]];

    // Tracking how long was spent on the last controller
    UIViewController *oldController = [self.childViewControllers objectAtIndex:self.selectedIndex];
    if (viewController != oldController) {
        NSTimeInterval secondsBetween = [self.start timeIntervalSinceNow];
        NSInteger sec = -1 * (secondsBetween + 0.5);          // round up and down
        if (sec > 0) {
            NSLog(@"Changing controllers from %@, %d seconds", [self getCorrectName:oldController], sec);
            [NSDictionary dictionaryWithObjectsAndKeys:[self getCorrectName:oldController], @"ViewController", sec, @"duration", nil];
            /*
            [[Mixpanel sharedInstance] track:@"tab_viewed"
                                  properties:[NSDictionary dictionaryWithObjectsAndKeys:
                                              [self getCorrectName:oldController], @"ViewController", sec, @"duration",
                                              nil]];
             */
            self.start = [NSDate date];
        }
    }
    return YES;
}

有任何想法吗?

4

1 回答 1

1

NSInteger 不是一个类。

使用 NSNumber

于 2013-04-18T03:39:36.610 回答