objective-c - 将项目转换为使用 ARC 时, "switch case is in p

将项目转换为使用 ARC 时,“switch case 在 protected 范围内”是什么意思? 我正在将项目转换为使用 ARC,使用 Xcode 4 Edit -> Refactor -> Convert to Objective-C ARC ... 我得到的错误之一是开关盒中的“某些”开关上的“开关盒在 protected 范围内”。

编辑, 代码如下:

错误标记在“默认”情况下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"";
    UITableViewCell *cell ;
    switch (tableView.tag) {
        case 1:
            CellIdentifier = @"CellAuthor";
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        cell.textLabel.text = [[prefQueries objectAtIndex:[indexPath row]] valueForKey:@"queryString"];
        break;
    case 2:
        CellIdentifier = @"CellJournal";
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        cell.textLabel.text = [[prefJournals objectAtIndex:[indexPath row]] valueForKey:@"name"];

        NSData * icon = [[prefJournals objectAtIndex:[indexPath row]] valueForKey:@"icon"];
        if (!icon) {
            icon = UIImagePNGRepresentation([UIImage imageNamed:@"blank72"]);
        }
        cell.imageView.image = [UIImage imageWithData:icon];

        break;

    default:
        CellIdentifier = @"Cell";
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }
        break;
    }


    return cell;
}

最佳答案

用大括号 {} 将每个案例本身括起来。那应该可以解决问题(在我的一个项目中对我有用)。

关于objective-c - 将项目转换为使用 ARC 时, "switch case is in protected scope"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7562199/

相关文章:

iphone - 开发一个 iPhone 应用程序需要多少钱?

ios - UIScrollView 以编程方式滚动到底部

ios - Objective-C 中的 "@private"是什么意思?

ios - 清除 NSUserDefaults

objective-c - block 声明语法列表

ios - 在 Swift 中实例化并展示一个 viewController

objective-c - #pragma 标记的意义​​是什么?为什么我们需要#pragma 标记

ios - UIActivityViewController 在 iOS 8 iPad 上崩溃

ios - UITableview:如何禁用某些行而不是其他行的选择

objective-c - 语义问题 : Property's synthesized getter