当我在UITableView上调用reloadData时,为什么我的应用程序崩溃了?

时间:2012-09-07 10:39:18

标签: xcode uitableview subview

我有一个UITableView,下面打印了cellForRowAtIndexPath。当我在tableView上调用reloadData时,应用程序崩溃,并且没有明确的EXC_BAD_ACCESS或任何东西 - 它只是返回main。自从我添加标签子视图以来,问题就出现了,这让我觉得发布子视图/重用单元格可能会有一些问题。

任何人都可以看到导致问题的原因吗?

提前致谢,

以下是代码:

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

    static NSString *CellIdentifier = @"MyCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    //---
    for(UIView *eachView in [cell subviews])
        [eachView removeFromSuperview];

    //Initialize cell label
    UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 290, 25)];
    [myLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:14.0]];
    [myLabel setTextColor:[UIColor darkGrayColor]];
    myLabel.text =@"Label";
    [cell addSubview:myLabel];
    [myLabel release];

    return cell;

}

0 个答案:

没有答案
相关问题