执行tableView的cellForRowAtIndexPath方法后,iPhone应用程序崩溃

时间:2011-02-21 13:55:03

标签: iphone objective-c cocoa-touch uitableview ios4

执行tableView

的cellForRowAtIndexPath方法后,应用程序崩溃

进入:

UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]

并崩溃了。

控制台中没有显示错误。它在Xcode的状态栏中显示 EXC_BAD_EXCESS

可能出现什么问题?

编辑1:

这是我的tableView的cellForRowAtIndexPath方法中的整个代码:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
  {

static NSString *CellIdentifier = @"Cell";
static NSString *newCellIdentifier = @"NewCell";

UITableViewCell *cell = nil;
NSUInteger row = [indexPath row];
NSUInteger count;
if (searching==YES) {
    count = [searchCellTextArray count];
}else {
    count = [cellTextArray count];
} 

if(row==count)
      {

    cell = [tableView dequeueReusableCellWithIdentifier:newCellIdentifier];
    if (cell == nil) 
               {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleDefault 
                 reuseIdentifier:newCellIdentifier] autorelease];
    }
    cell.textLabel.text = @"Load more items...";


    cell.textLabel.textColor = [UIColor blueColor];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14];

}
else 
      {
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
              {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }


    UIImage *cellImage = [[UIImage alloc] init];
    NSString *imgName;

    //Searching


    if(searching==YES && [searchCellTextArray count] != 0) 
               {

        NSString *decodedImageName = [NSString stringWithUTF8String:[[[showSearchImageArray objectAtIndex:indexPath.row]valueForKey:@"image"] cStringUsingEncoding:[NSString defaultCStringEncoding]]];
        imgName = decodedImageName;

        cell.textLabel.textColor = [UIColor redColor];
        cell.textLabel.text=[searchCellTextArray objectAtIndex:indexPath.row];

        cell.detailTextLabel.font= [UIFont boldSystemFontOfSize:18];
        cell.detailTextLabel.textColor = [UIColor blackColor];
        cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.detailTextLabel.numberOfLines= [lableNameArray count]+2;
        cell.detailTextLabel.text = [searchDetailTextArray objectAtIndex:indexPath.row];
    }
    else
              { //searching 

        NSString *decodedImageName = [NSString stringWithUTF8String:[[[showImageArray objectAtIndex:indexPath.row] valueForKey:@"image"] cStringUsingEncoding:[NSString defaultCStringEncoding]]];

        imgName = decodedImageName;


        cell.textLabel.textColor= [UIColor redColor];
        cell.textLabel.text = [cellTextArray objectAtIndex:indexPath.row];



        cell.detailTextLabel.font= [UIFont boldSystemFontOfSize:18];
        cell.detailTextLabel.textColor = [UIColor blackColor];
        cell.detailTextLabel.numberOfLines= [lableNameArray count]+2;
        cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.detailTextLabel.text = [detailTextArray objectAtIndex:indexPath.row];

    }

    if (imgName !=(NSString*)[NSNull null] && ![imgName isEqualToString:@""] && ![imgName isEqualToString:@"X"]) 
              {
        NSLog(@" Image Name : %@",imgName);

        NSString *documentsDirectory = [self getImagePath];
        NSError *error1;
        NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error1];
        if (files == nil) 
                        {
            NSLog(@"Error reading contents of documents directory: %@", [error1 localizedDescription]);
        }


        for (NSString *file in files) 
                        {
            NSLog(@"Loop Entered");
            if([file isEqualToString:[NSString stringWithFormat:@"%@_thumb.png",imgName]])
                  {
                NSLog(@"Image: %@ %@",file,imgName);
                NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:file];

                cellImage = [UIImage imageWithContentsOfFile:fullPath];
                NSLog(@"Full Path: %@",fullPath);

            }

        }

        cell.imageView.image = cellImage;
    }
              else 
              {
        cell.imageView.image = [UIImage imageNamed:@"GlossaryGhostImg1.png"];
    }

}
NSLog(@"Cell For Row At Index Path Done");
return cell;
}

这里是否有内存泄漏,我是否过度释放了任何对象?

2 个答案:

答案 0 :(得分:1)

可能有很多东西:你返回垃圾箱。你释放了你的细胞太多次了。您自动释放了电池的某些组件太多次了。听起来像是内存管理问题,请仔细检查您的保留/发布。并发布您的cellForRowAtIndexPath代码。

答案 1 :(得分:0)

尝试添加NSZombie环境变量。然后检查您的应用。也许你会找到崩溃的根本原因。