0

嗨,我的应用程序在滚动 tableview 时崩溃,并使用 LowMemory 维护崩溃日志名称。谁能告诉我我该如何管理这个。我使用的代码在这里:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    NSLog(@" %i",indexPath.section);

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //cell=nil;
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    UIImageView *cellBg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 768, 90)];
    cellBg.image=[UIImage imageNamed:@"Cellbg.png"];
    [cell addSubview:cellBg];

    UILabel *lblRecipeBorder=[[UILabel alloc]initWithFrame:CGRectMake(105, 5, 640, 80)];
    lblRecipeBorder.backgroundColor=[UIColor blackColor];
    lblRecipeBorder.layer.borderWidth=5.0;
    lblRecipeBorder.layer.cornerRadius=8.0;
    lblRecipeBorder.layer.borderColor=[[UIColor darkGrayColor] CGColor];
    [cell addSubview:lblRecipeBorder];

    UIImageView *RecipeeImg=[[UIImageView alloc]initWithFrame:CGRectMake(20, 5, 100, 80)];
    RecipeeImg.backgroundColor=[UIColor clearColor];
    RecipeeImg.layer.borderWidth=5.0;
    RecipeeImg.layer.cornerRadius=8.0;
    RecipeeImg.layer.borderColor=[[UIColor darkGrayColor] CGColor];
    RecipeeImg.image=[UIImage imageNamed:[[appdelegate.arrFiderTool objectAtIndex:indexPath.row] objectForKey:@"RecipestepPics"]];
    RecipeeImg.layer.masksToBounds = YES;
    [cell addSubview:RecipeeImg];

    UILabel *lblRecipee=[[UILabel alloc]initWithFrame:CGRectMake(140, 10, 620, 70)];
    lblRecipee.backgroundColor=[UIColor clearColor];
    [lblRecipee setNumberOfLines:2];
    lblRecipee.textColor=[UIColor colorWithRed:255.0/255.0 green:52.0/255.0 blue:179.0/255.0 alpha:1.0];
    //lblRecipee.font=[UIFont boldSystemFontOfSize:18.0];
    lblRecipee.font=[UIFont fontWithName:@"Noteworthy-Bold" size:18.0];
    //[lblMeetingId setFont:[UIFont fontWithName:@"Times New Roman" size:14]];
    lblRecipee.text=[[appdelegate.arrFiderTool objectAtIndex:indexPath.row] objectForKey:@"RecipeName"];
    [cell addSubview:lblRecipee];

    [RecipeeImg release];
    [lblRecipee release];
    [cellBg release];
    [lblRecipeBorder release];

   // }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
}
4

2 回答 2

1

您应该重用标签和图像视图来添加单元格。您可以通过子类化UITableViewCell或提供视图标签来做到这一点。在我看来,子类化是最好的方法,但现在我将为您提供一个标记视图的示例:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    NSLog(@" %i",indexPath.section);

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

   UIImageView *recipeImageView = nil;
   UILabel *recipeLabel = nil;

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        cell.selectionStyle=UITableViewCellSelectionStyleNone;

        UIImageView *cellBg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 768, 90)];
        cellBg.image = [UIImage imageNamed:@"Cellbg.png"];
        [cell addSubview:cellBg];

        UILabel *lblRecipeBorder=[[UILabel alloc]initWithFrame:CGRectMake(105, 5, 640, 80)];
        lblRecipeBorder.backgroundColor=[UIColor blackColor];
        lblRecipeBorder.layer.borderWidth=5.0;
        lblRecipeBorder.layer.cornerRadius=8.0;
        lblRecipeBorder.layer.borderColor=[[UIColor darkGrayColor] CGColor];
        [cell addSubview:lblRecipeBorder];

        UIImageView *recipeImageView =[[UIImageView alloc]initWithFrame:CGRectMake(20, 5, 100,    80)];
        recipeImageView.backgroundColor=[UIColor clearColor];
        recipeImageView.layer.borderWidth=5.0;
        recipeImageView.layer.cornerRadius=8.0;
        recipeImageView.layer.borderColor=[[UIColor darkGrayColor] CGColor];
        recipeImageView.layer.masksToBounds = YES;
        recipeImageView.tag = 456;
        [cell addSubview:recipeImageView];

        UILabel *recipeLabel=[[UILabel alloc]initWithFrame:CGRectMake(140, 10, 620, 70)];
        recipeLabel.backgroundColor=[UIColor clearColor];
        [recipeLabel setNumberOfLines:2];
        recipeLabel.textColor=[UIColor colorWithRed:255.0/255.0 green:52.0/255.0 blue:179.0/255.0 alpha:1.0];
        recipeLabel.font=[UIFont fontWithName:@"Noteworthy-Bold" size:18.0];
        recipeLabel.tag = 457;
        [cell recipeLabel];

        [recipeImageView release];
        [recipeLabel release];
        [cellBg release];
        [lblRecipeBorder release];
    } else {
        recipeImageView = [cell viewWithTag:456];
        recipeLabel = [cell viewWithTag:457];
    }

    NSDictionary *item = [appdelegate.arrFiderTool objectAtIndex:indexPath.row];

    recipeImageView.image = [UIImage imageNamed:[item objectForKey:@"RecipestepPics"]];
    recipeLabel.text = [item objectForKey:@"RecipeName"];


    return cell;
}
于 2013-09-25T10:07:40.317 回答
-1

改变:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

至:

UITableViewCell *cell [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
于 2013-09-25T10:09:43.830 回答