-2

uitableview をスクロールしてから uitableview の入力配列に新しい項目を追加しようとするとクラッシュする

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

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

    if([selected_table_string isEqualToString:@"table_for_category"])
    {
       [cell.contentView addSubview:[self tab_label:[NSString stringWithFormat:@"%@",[AppDelegate.category_arr objectAtIndex:indexPath.row]] fram:CGRectMake(10, 3, 200, 25)]];

        if([AppDelegate.selected_category_arr_item containsObject:[AppDelegate.category_arr objectAtIndex:indexPath.row ]])
        {
           [cell.contentView addSubview:[self img_name:@"chk_box_chk.png" frm:CGRectMake(140, 3, 30, 25)]];
        }
        else
        {
           [cell.contentView addSubview:[self img_name:@"chk_box.png" frm:CGRectMake(140, 3, 30, 25)]];
        }
    }

    else if ([selected_table_string isEqualToString:@"table_for_shape"])
    {
        [cell.contentView addSubview:[self tab_label:[NSString stringWithFormat:@"%@",[AppDelegate.shapeNames_arr objectAtIndex:indexPath.row]] fram:CGRectMake(10, 3, 200, 25)]];

        if([AppDelegate.selected_shapeNames_arrr_item containsObject:[AppDelegate.shapeNames_arr objectAtIndex:indexPath.row ]])
        {
            [cell.contentView addSubview:[self img_name:@"chk_box_chk.png" frm:CGRectMake(140, 3, 30, 25)]];
        }
        else
        {
            [cell.contentView addSubview:[self img_name:@"chk_box.png" frm:CGRectMake(140, 3, 30, 25)]];
        }


    }
    else if ([selected_table_string isEqualToString:@"table_for_color"])
    {
        [cell.contentView addSubview:[self tab_label:[NSString stringWithFormat:@"%@",[AppDelegate.color_arr objectAtIndex:indexPath.row]] fram:CGRectMake(10, 3, 200, 25)]];

        if([AppDelegate.selected_color_arr_item containsObject:[AppDelegate.color_arr objectAtIndex:indexPath.row ]])
        {
            [cell.contentView addSubview:[self img_name:@"chk_box_chk.png" frm:CGRectMake(140, 3, 30, 25)]];
        }
        else
        {
            [cell.contentView addSubview:[self img_name:@"chk_box.png" frm:CGRectMake(140, 3, 30, 25)]];
        }

    }
    else if ([selected_table_string isEqualToString:@"table_for_purity"])
    {
       [cell.contentView addSubview:[self tab_label:[NSString stringWithFormat:@"%@",[AppDelegate.purity_arr objectAtIndex:indexPath.row]] fram:CGRectMake(10, 3, 200, 25)]];

        if([AppDelegate.selected_purity_arr_item containsObject:[AppDelegate.purity_arr objectAtIndex:indexPath.row ]])
        {
           [cell.contentView addSubview:[self img_name:@"chk_box_chk.png" frm:CGRectMake(140, 3, 30, 25)]];
        }
        else
        {
            [cell.contentView addSubview:[self img_name:@"chk_box.png" frm:CGRectMake(140, 3, 30, 25)]];
        }

    }
    else if ([selected_table_string isEqualToString:@"table_for_Fluo"])
    {
        [cell.contentView addSubview:[self tab_label:[NSString stringWithFormat:@"%@",[AppDelegate.Fluo_arr objectAtIndex:indexPath.row]] fram:CGRectMake(10, 3, 200, 25)]];

        if([AppDelegate.selected_Fluo_arr_item containsObject:[AppDelegate.Fluo_arr objectAtIndex:indexPath.row ]])
        {
            [cell.contentView addSubview:[self img_name:@"chk_box_chk.png" frm:CGRectMake(140, 3, 30, 25)]];
        }
        else
        {
            [cell.contentView addSubview:[self img_name:@"chk_box.png" frm:CGRectMake(140, 3, 30, 25)]];
        }
    }
    else if ([selected_table_string isEqualToString:@"table_for_Cut"])
    {
        [cell.contentView addSubview:[self tab_label:[NSString stringWithFormat:@"%@",[AppDelegate.cut_arr objectAtIndex:indexPath.row]] fram:CGRectMake(10, 3, 200, 25)]];

        if([AppDelegate.selected_cut_arr_item containsObject:[AppDelegate.cut_arr objectAtIndex:indexPath.row ]])
        {
            [cell.contentView addSubview:[self img_name:@"chk_box_chk.png" frm:CGRectMake(140, 3, 30, 25)]];
        }
        else
        {
            [cell.contentView addSubview:[self img_name:@"chk_box.png" frm:CGRectMake(140, 3, 30, 25)]];
        }

    }
    else if ([selected_table_string isEqualToString:@"table_for_myselection"])
    {/////IT'S RECIEVED FOR MYSELECTIONS......
        //ParcelDetails *obj_parcel_selected_for_mail;
        obj_parcel_details_for_mail = [AppDelegate.mySelected objectAtIndex:indexPath.row];
        //cell.textLabel.text = [AppDelegate.mySelected objectAtIndex:indexPath.row];
        cell.textLabel.text = [NSString stringWithFormat:@"%@",obj_parcel_details_for_mail.parcelId];
        cell.textLabel.font = [UIFont fontWithName:@"Tahoma" size:18.0];


        UIButton *mail_to_Button =  [UIButton buttonWithType:UIButtonTypeCustom];
        [mail_to_Button setImage:[UIImage imageNamed:@"mail_icon_9"] forState:UIControlStateNormal];
        mail_to_Button.layer.shadowColor = [UIColor grayColor].CGColor;
        mail_to_Button.layer.shadowOffset = CGSizeMake(0, 3);
        mail_to_Button.layer.shadowOpacity = 1.8;
        mail_to_Button.layer.shadowRadius = 10.0;
        [mail_to_Button addTarget:self action:@selector(send_mail_Action) forControlEvents:UIControlEventTouchUpInside];
        [mail_to_Button setFrame:CGRectMake(530,15,40,40)];

        [cell.contentView addSubview:mail_to_Button];
    }

    return cell;
}
4

2 に答える 2

0

TableView のデータソースを更新する前に、[yourTableView reloadData];これを呼び出すだけで、データソース配列のスクロールおよび更新中にクラッシュが解決するはずです。

于 2012-08-24T14:29:51.963 に答える
0

サブビューが表示されるたびにセルにサブビューを追加していて、最終的にはメモリ不足になります (おそらくエラー メッセージやクラッシュが発生しないのはそのためです)。これを修正するために思いつく解決策は、このようにメソッドで作成時にサブビューにタグを付けることimg_name:frm:です。

subview.tag = 100;

およびセルのカスタマイズ コード内。

 for(UIView *view in cell.subviews){
   if(view.tag = 100)[view removeFromSuperview];
 }

edit* UIButton についても同じことを行う必要があります。

于 2012-08-24T14:27:27.803 に答える