【问题标题】:Reference counted object is used after being it is released引用计数的对象在被释放后使用
【发布时间】:2012-07-21 12:11:29
【问题描述】:

我收到内存警告,因为“引用计数对象在被释放后被使用”

为此,我也尝试过自动释放。但没用。

下面是给出警告的代码。问题是什么。请告诉我

UICustomSwitch *switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero];
                [switchView initWithFrame:CGRectMake(180,5,260,30)];
                [switchView setOn:YES];
                mySearchType = 1;
                [[switchView rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
                [[switchView leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
                [switchView addTarget:self action:@selector(switchToggled:)forControlEvents:UIControlEventValueChanged];
                [cell.contentView addSubview:switchView];

【问题讨论】:

  • 为什么你的 switchView 初始化了两次?
  • 我同意 luyuan 的观点,你可以第一次用 frame 来初始化它,而不是 cgrectzero。顺便说一句,我不认为您粘贴的代码显示了完整的图片 - 从代码来看,switchview 似乎没有被脱离上下文访问,所以嫌疑人是单元格 - 它可能已经被释放。你能把整个方法贴出来吗?

标签: iphone ios memory-management ios4


【解决方案1】:

更改以下代码

UICustomSwitch *switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero];
                [switchView initWithFrame:CGRectMake(180,5,260,30)];

进入

UICustomSwitch *switchView = [[UICustomSwitch alloc] initWithFrame:CGRectMake(180,5,260,30)];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-11
    • 2011-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    相关资源
    最近更新 更多