【问题标题】:Problems with "autorelease"“自动释放”的问题
【发布时间】:2012-07-04 16:47:22
【问题描述】:

我的“autorelease”有问题,查看我的代码:然后在“autorelease”中出现 2 条消息错误:

-'autorelease'不可用:在自动引用计数模式下不可用

与:

ARC 禁止发送“自动释放”的显式消息 //代码

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    return 25;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
  (NSIndexPath *)indexPath{ 
                           static NSString *CellIdentifier = @"Cell"; 
                           UITableViewCell *cell = [tableView
                                         dequeueReusableCellWithIdentifier:CellIdentifier];      
         if(cell==nil){
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ***autorelease***];

    } 


    // Configure the cell...
    cell.textLabel.text=[NSString stringWithFormat:@"Rental Property:%d", indexPath.row];
    NSLog(@"Rental Property %d", indexPath.row);
    return cell;    return cell;
}

有人可以帮忙吗?

谢谢!!

【问题讨论】:

    标签: objective-c release


    【解决方案1】:

    只需删除对-autorelease 的调用即可。在 ARC 模式下不需要它。

    【讨论】:

      【解决方案2】:

      如果这不是您的代码,而是您复制和粘贴的第三方库,您应该在 Targets-> Build Phases -> Compile Sources 和有问题文件的编译器标志下专门为实现文件关闭 ARC输入

      -fno-objc-arc

      【讨论】:

      • 这就是您要寻找的答案吗?
      【解决方案3】:

      使用 ARC 时不需要使用自动释放。 ARC 代表“自动引用计数”,它自动处理对象的保留和释放。

      【讨论】:

        猜你喜欢
        • 2012-03-16
        • 1970-01-01
        • 2011-11-19
        • 1970-01-01
        • 2011-06-04
        • 1970-01-01
        • 2011-11-09
        • 1970-01-01
        • 2011-05-03
        相关资源
        最近更新 更多