嗨,我从这段代码中收到以下错误:
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;
}
有任何想法吗?