2012-08-24 121 views
-2

我面临崩溃时,我滚动的UITableView,然后尝试在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

崩溃出现时的任何特定消息? – CBredlow

+0

不是消息它直接显示main.m类 –

+0

Dipak提出了一些更相关的代码和错误消息 – mangesh

回答

0

您每次添加子视图您的细胞,他们显示你是,最终,内存不足(这可能是你没有收到错误信息或崩溃的原因)。为了解决这个问题,想到的解决方案是在你的img_name:frm:这样的方法上标记你的创建子视图。

subview.tag = 100; 

和你的单元格内的自定义代码;

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

edit *对于你的UIButton应该做同样的事情。

+0

为什么在重新添加之前删除?为什么不重用它们? – Cyrille

+0

那么这只是第一个想到的,并且可能是他最容易实现的。 – ohr

0

在更新TableView的数据源之前,只需调用[yourTableView reloadData];这应该可以在滚动和更新数据源数组时解决您的崩溃问题。