更新
我把Zombies变成了......并且得到了这个错误:
*** -[CALayer retain]: message sent to deallocated instance 0x709d1a0
我正在经历一场对我没有任何意义的崩溃。在loadMediaList
我以编程方式创建多个按钮并为其分配操作(openMedia:
)。该操作具有“openURL”操作。一切都很好,直到行动被召唤;执行操作,在新窗口中打开,但一旦退出应用程序就会崩溃。我用不同的代码替换了“openURL”代码,它仍然崩溃......想法?
控制台中没有错误,我得到EXC_BAD_ACCESS
。控制台说:
sharedlibrary apply-load-rules all
Current language: auto; currently objective-c
kill
quit
Program ended with exit code: 0
我已经在这个问题上工作了几天,我无法弄明白。我的dealloc很棒,线程似乎运行良好,等等。我不知道这是否合法Stack Overflow,但我很乐意付钱帮助我解决这个问题。我的截止日期非常紧张。
希望你能帮忙!
-(IBAction)showMedia:(id)sender {
NSLog(@"Media Button was pressed");
//Begin Alert
[SVProgressHUD showInView:self.view status:@"Loading..."];
mediaScroll.delegate = self;
mediaScroll.frame = CGRectMake(15, 60, 240, 185);
mediaScroll.clipsToBounds = YES;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
statsBTN.frame = CGRectMake(272, 76, 48, 46);
donateBTN.frame = CGRectMake(272, 124, 48, 46);
shareBTN.frame = CGRectMake(272, 172, 48, 46);
mediaBTN.frame = CGRectMake(280, 220, 48, 46);
incViewPopUP.alpha = 0;
donViewPopUP.alpha = 0;
shareViewPopUP.alpha = 0;
mediaViewPopUP.alpha = 1;
[UIView commitAnimations];
[self loadMediaList];
[mediaBTN addTarget:self action:@selector(closePopUp:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)loadMediaList {
[self.productPointers removeAllObjects];
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"date_reported" ascending:NO] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray = [finalMediaList sortedArrayUsingDescriptors:sortDescriptors];
NSLog(@"Sorted Media Array: %@", sortedArray);
if (mediaLoaded == NO) {
NSDictionary *mediaPost;
for (mediaPost in sortedArray) {
NSDictionary *inside = (NSDictionary *)[mediaPost valueForKey:@"media"];
NSLog(@"Inside Array: %@", inside);
UIButton *mediaView = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
mediaView.frame = CGRectMake(0, (mx * 100), 225, 100);
mediaView.backgroundColor = [UIColor clearColor];
[mediaView addTarget:self action:@selector(openMedia:) forControlEvents:UIControlEventTouchUpInside];
mediaView.titleLabel.hidden = YES;
mediaView.titleLabel.alpha = 0;
mx++; NSLog(@"MX: %i", mx);
UILabel *mediaDesc = [[UILabel alloc] init];
mediaDesc.frame = CGRectMake(50, 20, 154, 40);
mediaDesc.backgroundColor = [UIColor clearColor];
mediaDesc.font = [UIFont fontWithName:@"Geogrotesque" size:12];
mediaDesc.textColor = UIColorFromRGB(0xc7c7c7);
mediaDesc.numberOfLines = 0;
mediaDesc.lineBreakMode = UILineBreakModeWordWrap;
mediaDesc.text = [inside valueForKey:@"description"];
UILabel *mediaType = [[UILabel alloc] init];
mediaType.frame = CGRectMake(50, 40, 154, 50);
mediaType.backgroundColor = [UIColor clearColor];
mediaType.font = [UIFont fontWithName:@"Geogrotesque" size:12];
mediaType.textColor = UIColorFromRGB(0xffffff);
mediaType.numberOfLines = 0;
mediaType.lineBreakMode = UILineBreakModeWordWrap;
mediaType.text = [[inside valueForKey:@"type"] uppercaseString];
UIImageView *mediaBorder = [[UIImageView alloc] initWithFrame:CGRectMake(0, 99.0, 220.0, 1.0)];
[mediaBorder setImage:[UIImage imageNamed:@"bottom_border.png"]];
UIImageView *mediaArrow = [[UIImageView alloc] initWithFrame:CGRectMake(214.0, 45.0, 6.0, 9.0)];
[mediaArrow setImage:[UIImage imageNamed:@"media_right_arrow.png"]];
if ([mediaType.text isEqualToString:@"VIDEO"]) {
UIImageView *mediaThumb = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 35.0, 30.0, 30.0)] autorelease];
[mediaThumb setImage:[UIImage imageNamed:@"media_play_icon.png"]];
[mediaView addSubview:mediaThumb];
[mediaThumb release];
[mediaView setTag:1];
[mediaView setTitle:[inside valueForKey:@"filename"] forState:UIControlStateNormal];
}
if ([mediaType.text isEqualToString:@"IMAGE"]) {
UIImageView *mediaThumb = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 35.0, 30.0, 22.0)] autorelease];
[mediaThumb setImage:[UIImage imageNamed:@"media_photo_icon.png"]];
[mediaView addSubview:mediaThumb];
[mediaThumb release];
[mediaView setTag:2];
[mediaView setTitle:[inside valueForKey:@"url"] forState:UIControlStateNormal];
}
[mediaView addSubview:mediaArrow];
[mediaView addSubview:mediaBorder];
[mediaView addSubview:mediaDesc];
[mediaView addSubview:mediaType];
[mediaScroll addSubview:mediaView];
[self.productPointers addObject:mediaView];
[mediaArrow release];
[mediaBorder release];
[mediaType release];
[mediaDesc release];
[mediaView release];
}
}
mediaLoaded = YES;
[mediaScroll setContentSize:CGSizeMake(225.0f, (mx * 100))];
//End Alert
[SVProgressHUD dismiss];
}
-(IBAction)openMedia:(id)sender {
NSLog(@"Media opened!");
NSString *tag = [NSString stringWithFormat:@"%d", [sender tag]];
NSLog(@"Tag: %@", tag);
videoID = [sender currentTitle];
NSString *videoURL = [[[NSString alloc] initWithFormat:@"http://www.vimeo.com/%@", videoID] autorelease];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];
NSLog(@"Video URL: %@", videoURL);
}
答案 0 :(得分:1)
在调试器中启用malloc stack logging,guard malloc和zombie enabled,然后运行:
(gdb) info malloc-history 0x1b18b0
其中0x1b18b0
是具有错误访问错误的事物的地址。它应该为您提供有关代码中问题所在位置的更多信息。
See this article for better instructions
此外,可能帮助的一些代码想法
改变这个:
videoID = [sender currentTitle];
NSString *videoURL = [[[NSString alloc] initWithFormat:@"http://www.vimeo.com/%@", videoID] autorelease];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];
要:
videoID = [sender currentTitle];
if (videoID) {
// no need to alloc then set autorelease, just used a named initializer since they autorelease by default:
NSString *videoURL = [NSString stringWithFormat:@"http://www.vimeo.com/%@", videoID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];
} else {
// deal
}