- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
滚动 UITableview
时出现以下错误。EXC_BAD_ACCESS
,-[CFString keep]:发送到已释放实例的消息
我如何找到已释放的实例...?这是我的 noOfRowsinsection 代码
for(int i=0;i<size;i++)
{
NSString *CellIdentifier1;
if(universalApp==2)
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];
CellIdentifier1 = @"CustomThumbImageTableCell_iphone";
cell = [[[CustomThumbImageTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];
//NSLog(@">>>>> Creating image >>>>>>>>");
//cell.thumbImageView = [[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)];
cell.thumbImageView = [[[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)] autorelease];
[imgViewArray addObject:cell.thumbImageView];
[cell.thumbImageView release];
[pool release];
}
这是我的 cellforRow 代码
enter code hereif(universalApp==2)
{
NSLog(@"iphone cell>>>>>>>>>>>>>>>>>>>>>>");
CustomThumbImageTableCell *cell = nil;
@try
{
static NSString *CellIdentifier = @"CustomThumbImageTableCell_iphone";
int currentRow = [indexPath row] ;//+ skippedItems;
//NSLog(@">>>>>>>>>>>>Current Table row = %d, %d, %d", loadedCellArray.count, currentRow, [Table numberOfRowsInSection:0]);
/*if(loadedCellArray.count > currentRow + 1 && [loadedCellArray objectAtIndex:(currentRow)] != nil)
{
NSLog(@"Image updated = %d", ( currentRow));
cell = (CustomThumbImageTableCell_iphone *) [loadedCellArray objectAtIndex:(currentRow )];
}
else
{*/
/*if(loadedCellArray.count > currentRow + 1 )// && [loadedCellArray objectAtIndex:(currentRow)] != nil)
// if( [loadedCellArray objectAtIndex:(currentRow)] != nil)
{
//NSLog(@"Image updated = %d", ( currentRow));
cell = (CustomThumbImageTableCell_iphone *) [loadedCellArray objectAtIndex:([indexPath row] )];
if(!isScrollingUp)
{
//scrollCount++;
[loadedCellArray removeLastObject];
}
isScrollingUp = YES;
}
else*/
{
static NSString *CellIdentifier = @"CustomThumbImageTableCell_iphone";
static NSString *CellIdentifier1 = @"CustomThumbImageTableCell_iphone";
//UITableViewCell *cell;
if(cell==nil)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[CustomThumbImageTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
cell = [[[CustomThumbImageTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSLog(@">>>>>>>>>..... %d, %d, %@", imgViewArray.count, indexPath.row, (((int)imgViewArray.count- 1) < (int)indexPath.row) ? @"YES" : @"NO");
/*if(((int)imgViewArray.count- 1) < (int)indexPath.row)
{
// NSLog(@">>>>> Creating image >>>>>>>>");
cell.thumbImageView = [[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)];
[imgViewArray addObject:cell.thumbImageView];
}
else {
cell.thumbImageView = (CustomImageView *) [imgViewArray objectAtIndex:indexPath.row];
}*/
//NSLog(@"img array = %@,%d",imgViewArray,imgViewArray.count);
cell.thumbImageView =[imgViewArray objectAtIndex:indexPath.row];
cell.thumbImageView.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:cell.thumbImageView];
cell.thumbImageView.index = (int)indexPath.row;
@try
{
{
BOOL isFound = NO;
do
{
@try {
NSArray *array1 = [contentString componentsSeparatedByString:@"@@#"];
NSArray *array2 = [[array1 objectAtIndex:currentRow ] componentsSeparatedByString:@"##"];
NSString *str = [NSString stringWithFormat:@"%@", [array2 objectAtIndex:0]];
str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(104, 6, 141, 96)];
name.textAlignment = UITextAlignmentCenter;
name.font = [UIFont fontWithName:@"Arial" size:17.0];
name.numberOfLines = 3;
name.backgroundColor = [UIColor clearColor];
name.textColor = [UIColor whiteColor];
cell.catalogName = name;
[cell.catalogName setText:[NSString stringWithFormat:@"%@", str]];
[cell.contentView addSubview:cell.catalogName];
//[name release];
name = [[UILabel alloc] initWithFrame:CGRectMake(107, 89, 193, 21)];//107,89,193
name.textAlignment = UITextAlignmentCenter;
name.font = [UIFont fontWithName:@"Arial" size:13.0];
name.textColor = [UIColor whiteColor];
name.numberOfLines = 3;
name.backgroundColor = [UIColor clearColor];
name.alpha = 0.26;
cell.pageNo = name;
[cell.contentView addSubview:cell.pageNo];
//[name release];
if((searchId != 2 && (isLineNameSearchEnabled == 0)) || searchInCatalogFlag == 1)
//cell Page No//pageNoLabel
//NSLog(@"cell for row.......");
[cell.pageNo setText:[NSString stringWithFormat:@"Page No: %@", [array2 objectAtIndex:(array2.count - 2)]]];
{
}
NSLog(@" thumb image = %@",[NSString stringWithFormat:@"%@%@", baseURL, [array2 objectAtIndex:1]]);
//[cell.thumbImageView setImageURL:@"http://www.zoomcatalog.com/sites/default/files/catalogs/27705_Abex2010/images/thumbnails/Thumb-1.jpg"];
[cell.thumbImageView setImageURL:[NSString stringWithFormat:@"%@%@", baseURL, [array2 objectAtIndex:1]]];
[NSThread detachNewThreadSelector:@selector(initThread) toTarget:cell.thumbImageView withObject:nil];
[cell.thumbImageView setPageNo:((searchId == 2 || (isLineNameSearchEnabled && searchInCatalogFlag == 0)) ? 0 : (int)currentRow)];
UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(264, 33, 36, 34)];
img.contentMode = UIViewContentModeScaleToFill;
[img setImage:cellArrow];
[cell.contentView addSubview:img];
[img release];
[cell.catalogName release];
//>>>> [cell.pageNoLabel release];
[cell.thumbImageView release];
isFound = YES;
}
@catch (NSException * e) {
//skippedItems++;
currentRow = [indexPath row] + 1;
}
}
while (!isFound);
/*if(isScrollingUp)
{
//scrollCount++;
[loadedCellArray removeLastObject];
}
isScrollingUp = NO;
currentRow =indexPath.row;
// cell = (CustomThumbImageTableCell_iphone *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//cell = (CustomThumbImageTableCell_iphone *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomThumbImageTableCell_iphone" owner:self options:nil];
//cell = (CustomThumbImageTableCell_iphone *) [loadedCellArray objectAtIndex:(currentRow )];
cell = self.cell;
self.cell = nil;
}
NSLog(@"Image loaded from source= %d,", ( currentRow));
//if(loadedCellArray.count > currentRow + 1)
// NSLog(@"Image loaded from source cell array ref= %@", [loadedCellArray objectAtIndex:(currentRow)]);
/*if(currentRow == ([Table numberOfRowsInSection:0] - 1))
{
cell.catalogName.text = @"50 More";
NSLog(@">>>>>>>>>>>>>>>>>>>>> End cell....");
return cell;
}
/////
// if(true)
// return cell;
@try
{
{
BOOL isFound = NO;
do
{
@try {
NSArray *array1 = [contentString componentsSeparatedByString:@"@@#"];
NSArray *array2 = [[array1 objectAtIndex:currentRow] componentsSeparatedByString:@"##"];
NSString *str = [NSString stringWithFormat:@"%@", [array2 objectAtIndex:0]];
str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// NSLog(@"&&&&&&&&&&&&&&&&& %@", str);
[cell.catalogName setText:[NSString stringWithFormat:@"%@", str]];
if((searchId != 2 && (isLineNameSearchEnabled == 0)) || searchInCatalogFlag == 1)
[cell.pageNo setText:[NSString stringWithFormat:@"Page No: %@", [array2 objectAtIndex:(array2.count - 2)]]];
// NSLog(@"Background color has been set....%d", i);
//NSLog(@")
//NSLog(@"Catalog %d = %@", currentRow, [array1 objectAtIndex:currentRow]);
// NSLog(@"Image URL = %@", [NSString stringWithFormat:@"%@%@", baseURL, [array2 objectAtIndex:1]]);
[cell.thumbImageView setImageURL:[NSString stringWithFormat:@"%@%@", baseURL, [array2 objectAtIndex:1]]];
//[cell.thumbImageView setContentString:contentString];
//if(searchId == 2)
// [cell.thumbImageView setContentString:[NSString stringWithFormat:@"%@", [array2 objectAtIndex:(array2.count - (isLineNameSearch ? 2 : 2))]]];
[cell.thumbImageView performSelectorOnMainThread:@selector(initThread) withObject:nil waitUntilDone:NO];
[cell.thumbImageView setPageNo:(searchId == 2 ? @"0" : [indexPath row])];
isFound = YES;
}
@catch (NSException * e) {
//skippedItems++;
currentRow = [indexPath row] + 1;
}
*/
// }
// while(!isFound);// && currentRow < [Table numberOfRowsInSection:0]);
//[imgViewArray addObject:cell.thumbImageView];
// [imgViewArray retain];
//[label setTextColor:[UIColor blackColor]];
//[label setTextAlignment:UITextAlignmentCenter];
/* UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(7 + ((i % 3) * (96 + 8)) , 9 + ((i / 3) * (140 + 10)), 98, 142)];
[label setBackgroundColor:[UIColor grayColor]];
[scrollView addSubview:label];
[imgViewArray addObject:imgView];
[scrollView addSubview:imgView];
if(i % 3 == 0)
{
[scrollView setContentSize:CGSizeMake(scrollView.contentSize.width, scrollView.contentSize.height + (140 + 10))];
}*/
}
//[imgViewArray retain];
// [cellArray retain];
}
最佳答案
当您遇到内存管理问题时,您可以执行以下操作:
[_NSZombie release]
插入一个断点。这应该有望打破导致问题的线路。根据您的代码,以下行可能是罪魁祸首。
[cell.thumbImageView release]; // NOT GOOD
类似地,在您的其他代码中:
[cell.thumbImageView release]; // NOT GOOD
[cell.catalogName release]; // NOT GOOD
您将自动释放的对象设置为单元格的 thumbImageView
和 catalogName
属性,但您仍在尝试释放它。这不是 Cocoa 内存管理的工作原理。您不拥有 cell.thumbImageView
或 cell.catalogName
,因此您不应释放它们。
关于iphone - “EXC_BAD_ACCESS” , “-[CFString release]: message sent to deallocated instance” 在表格中滚动时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4930664/
我遇到了一些应用程序崩溃的问题,我需要一些指导才能修复它。我有一个带有主视图和模态视图的应用程序,非常类似于默认的翻转实用模板。当我第一次运行该应用程序时,一切都运行良好,包括模态视图。但是,当我返回
UPDATE: I updated the correction of my definition of Realm, I still get the error. I'm using Swi
我正在尝试用带有c的sqlite3创建一个CGI可执行文件。但我收到错误exc_badd_access,我不知道问题出在哪里。我的代码是:。main.c。sqlite.h。Sqlite.c。Confi
我正在尝试用带有c的sqlite3创建一个CGI可执行文件。但我收到错误exc_badd_access,我不知道问题出在哪里。我的代码是:。Main.c。sqlite.h。Sqlite.c。Confi
我正在尝试暂停 AVAudioPlayer如果当前正在播放。当我调试我的代码并检查时 AVAudioPlayer ,我看是分配的。当我尝试访问它的方法/属性(即 myAudioPlayer isPla
我正在使用 xcode 用 C 语言编写这个简单的程序。 #include int main() { double A[200][200][2][1][2][2]; int B[2
这是我得到的错误 Thread 1:EXC_BAD_ACCESS (code=2, address=0xb7ffffc) 在这条线上 [[NSNotificationCenter defaultCen
我的 iPhone 应用程序出现问题,出现 EXC_BAD_ACCESS,出现一些内存泄漏,但这些问题现已修复,所以我不确定发生了什么。我意识到我没有提供很多信息,但我真的不知道发生了什么。 打开初始
//adds a button to scroll list -(void) addNode:(NSString *) atitle{ UIButton *btn = [UIButton
我几乎完成了我的第一个应用程序,但我遇到了一个奇怪的 EXC_BAD_ACCESS,这种情况几乎一直在发生。 这是跟踪: #0 0x02adba93 in objc_msgSend #1 0x0702
我一直在研究核心数据,并开始编写一些方法来查询不同日期范围的数据。我的核心数据模型非常简单(名为 Smoke 的实体,具有一个字段 - 时间戳(日期类型)。 当我执行代码时,会返回正确的计数,但出现自
我有以下代码: ABAddressBookRef ab; ab = ABAddressBookCreate(); int len = (int) ABAddressBookGetPersonCount
希望有人可以帮助我调试这个问题,因为 EXC_BAD_ACCESS 是我收到的唯一错误。我也尝试过打开 NSZombieEnabled,但据我所知,没有获得更多信息。 问题。我有四个实体: A ->
我正在 tableView 上加载自定义单元格,并在 tableView 中返回 50 行。一些行数显示在表格 View 中,但是当滚动表格 View 时,我的自定义单元格不显示,并且出现错误 "EX
我正在尝试使用 NSLog 来打印控制台消息。问题是有时我在调用它时收到“EXC_BAD_ACCESS”错误 -(void)willRotateToInterfaceOrientation:(UIIn
这是我使用音频队列生成噪音的代码: http://pastebin.com/Kn8GU72J 问题是我的代码生成了 EXC_BAD_ACCESS。问题似乎出在作业中 MAAudioManage
我正在开发适用于 iOS 的 OpenGL ES 2 应用程序。今天早上(没有更改任何代码)我开始从 sgxTextureGetImageRowBytes 抛出 EXC_BAD_ACCESS。 #0
我在这里完全迷路了。 我的应用程序中有Google Analytics(分析),可查看有多少用户从UITableView进入detailview 我在viewDidLoad方法中添加了Google A
我是 Cocoa 新手,正在编写一个简单的应用程序来学习使用 Core Data,但它因 EXC_BAD_ACCESS 而崩溃。尝试了几种方法,但尚未找到解决方案。正如我所说,我对 Cocoa 的经验
以下代码使应用程序崩溃,我不知道为什么。它不规则地崩溃,这意味着有时单击一行时 ImageView 可以显示 30 次,有时当我选择一行时它会第二次崩溃。 仅供引用:事件指示器、操作表和变量 imag
我是一名优秀的程序员,十分优秀!