重新加载UITableView时遇到EXC_BREAKPOINT

时间:2013-06-03 12:18:25

标签: ios uitableview

请帮助。

我创建了一个自定义UITableView,它从UITableViewCell获取自定义单元格。然后我使用标签访问其子视图。 以下是用于cellForRowAtIndexPath:

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

UITableViewCell *cell= [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%d",indexPath.row);
EmailContactDetails* data = [emailContactDetailsArray objectAtIndex:indexPath.row];

if (cell == nil)
{
    if ([tableView isEqual:mTableEmailList])
    {

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"iBOCEmailTableViewCell" owner:self options:nil];
        cell = (UITableViewCell *)[nib objectAtIndex:0];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        UIView *view1=(UIView *)[cell viewWithTag:1];
        UIView *view2=(UIView *)[cell viewWithTag:2];

        iBOCUIButton *btnRowTap=(iBOCUIButton *)[cell viewWithTag:18];
        [btnRowTap addTarget:self action:@selector(didButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];

        [view1 setHidden:NO];


        for (UIView *view in view1.subviews) {
            if ([view isKindOfClass:[iBOCUILabel class]]) {
                [(iBOCUILabel*)view setTextColor:[UIColor colorWithRed:102.0/255.0 green:102/255.0 blue:102/255.0 alpha:1.0f]];
            }
        }
        for (UIView *view in view2.subviews) {
            if ([view isKindOfClass:[iBOCUILabel class]]) {
                [(iBOCUILabel*)view setTextColor:[UIColor colorWithRed:102.0/255.0 green:102/255.0 blue:102/255.0 alpha:1.0f]];
            }
        }

        iBOCUILabel *lblEmailType=(iBOCUILabel*)[cell viewWithTag:11];

        [lblEmailType setText:data.emailType.deCode];


        if (!(indexPath.row == tableRowExpanded))            //...for row not expanded
        {
            [cell setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"white_bar_851x94.png"]]];
            [btnRowTap setImage:[UIImage imageNamed:@"down_arrow_grey_17x12.png"] forState:UIControlStateNormal];
            [btnRowTap setBackgroundImage:nil forState:UIControlStateNormal];
            [view2 setHidden:YES];
        }
        if (indexPath.row==tableRowExpanded)                    //..for row expanded
        {

            for (UIView *view in view1.subviews) {
                if ([view isKindOfClass:[iBOCUILabel class]]) {
                    [(iBOCUILabel*)view setTextColor:[UIColor whiteColor]];
                }
            }

            view2.hidden=NO;
            [cell setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"expanded_box_851x427.png"]]];
            [btnRowTap setImage:[UIImage imageNamed:@"white_arrow_17x13.png"] forState:UIControlStateNormal];
            [btnRowTap setBackgroundImage:nil forState:UIControlStateNormal];

            iBOCUIButton *btnCancel=(iBOCUIButton *)[cell viewWithTag:24];

            [btnCancel setBackgroundImage:[UIImage imageNamed:@"grey_btn_97x35.png"] forState:UIControlStateNormal];
            [btnCancel setTitleColor:[UIColor colorWithRed:102.0/255.0 green:102/255.0 blue:102/255.0 alpha:1.0f] forState:UIControlStateNormal];
            [btnCancel addTarget:self action:@selector(didButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];

        }
    }
}

return cell;
}

我收到以下错误:EXC_BREAKPOINT(code==EXC_i386_BPT, subcode==0x0). 在打开Zombie模式时,我收到以下消息:

 -[CALayer release]: message sent to deallocated instance 0x1650a660

这种情况发生在两种情况:

  1. 当我重新加载表格时。
  2. 当我滚动表格并调用cellForRowAtIndexPath时。
  3. 我理解它存在内存问题,但我无法追查其来源。

    任何人都可以帮助我吗?我没有关于调试的非常清晰的概念。 谢谢

    编辑: 其中一个问题得到克服: - “2.当我滚动表格并调用cellForRowAtIndexPath时。” 通过添加一行代码:

    [cell retain];
    

    在这一行之后:“cell =(UITableViewCell *)[nib objectAtIndex:0];” 我不明白它为什么会发生但它在滚动时没有显示任何错误。虽然如果我使用以下方法重新加载表,错误仍然相同:

    [mTableEmailList reloadData];
    

0 个答案:

没有答案