0
嗨,我从这个代码收到以下错误:EXC_BAD_ACCESS(代码= 2,地址= 0x3)
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;
}
任何想法?
它表示指针被破坏。在你的情况下,这可能是因为你传递一个NSInteger作为指针。 (提示:不要这么做!) – 2013-04-18 02:43:57
NSDictonaries不能包含非对象(或者当它们试图保留它的值时它们会崩溃)。将'sec'包装在NSNumber中。 – CodaFi 2013-04-18 02:44:11
是的,尽管它的“NS”的前缀,NSInteger是*不*类 – borrrden 2013-04-18 03:13:25