[英]autorelease alternative on ios5
ios5中自動發布的替代方法是什么? 以前,可以使用以下表視圖方法:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
static NSString *TableIdentifier = @"TableIndentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableIdentifier]autorelease];
}
cell.textLabel.text = [arrAccounts objectAtIndex:row];
return cell;
}
現在我怎么收到消息“ ARC禁止”和“自動發布不可用” ...這方面的解決方法是什么?
只需刪除自動發布,ARC即可為您完成工作
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableIdentifier];
該死的魔術
刪除自動釋放呼叫。 AFAIK編譯器足夠聰明,可以意識到應該自動釋放它並為您合成適當的調用。
如果不想對當前文件進行ARC所需的更改,則可以使用該文件的新-fno-objc-arc編譯器標志為特定文件禁用ARC。 使用新的-fobjc-arc編譯器標志啟用了ARC。 如果更方便地對某些文件使用手動引用計數,則可以選擇按文件使用ARC。 更多信息: http : //developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.