ios 开发中遇到 UIAlertView 窗口无法release的问题

本文详细介绍了在Objective-C项目中使用ARC模式时遇到手动release报错的问题,并提供了调整ARC设置的解决方案,以避免该错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


   程序中有如下代码:
    UIAlertView *alert = [[UIAlertView alloc]   
                          initWithTitle:@"Something was done."   
                          message:@"ok"   
                          delegate:self   
                          cancelButtonTitle:@"OK!"   
                          otherButtonTitles:nil];  
    [alert show];  
    [alert release]; 

在xcode环境中 报告错误

 error: 'release' is unavailable: not available in automatic reference counting mode [3]


解决办法:

在xcode中选择 project navigator (最左边的视窗)->选中项目名称 ->在主窗口中显示的 project 和targets中选择 project面板->选择building settings-> 在Apple LLVM compiler 3.0 -language 中选择 Ojective-C Automatic Reference couting 选项,把yes 修改成no。


也可以在建立项目的时候不要选择Using Automatic Reference counting 选项。


ARC 是4.2新提供的选项


相关文章可以查看

http://stackoverflow.com/questions/6914453/dealloc-method-gone-from-the-viewcontroller-implementation-file-template-in-xcod


主要意思是


Most likely you have created a project that uses the new ARC (Automatic Reference Counting) and therefore do not need the dealloc method because calling retain or release is no longer allowed when compiling with this option.

所以不需要去手工release了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值