【问题标题】:iPhone getting ABC Forbids explicit message sent of auto release [duplicate]iPhone获得ABC禁止发送自动释放的明确消息[重复]
【发布时间】:2012-10-03 22:44:26
【问题描述】:

我正在将一些代码从一个项目复制到另一个项目以填充表格视图, 我收到此错误

ABC Forbids explicit message sent of auto release

当我尝试创建 UITableViewCell 对象时。

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
       // this line produces the error
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

【问题讨论】:

  • 哈哈。你是说 ARC 吗?

标签: iphone


【解决方案1】:

我认为您的意思是 ARC(不是 ABC)?当您的项目使用自动引用计数时,您不需要调用releaseretainautorelease。在这种情况下,您可以摆脱自动释放调用,您的代码应该可以编译。

【讨论】:

    【解决方案2】:

    如果您不使用 ARC(或 ABC :D),您应该只在 release 它通常在 -(void)delloc 如果你使用删除代码行(只是autorelease)。

    【讨论】:

    • 在非 ARC 代码中,这种方法仍然需要发布!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 2023-03-29
    • 2013-10-31
    • 2011-06-14
    • 1970-01-01
    相关资源
    最近更新 更多