这是一个switch语句,我发现了错误:

        switch (transaction.transactionState) {

        case SKPaymentTransactionStatePurchasing:

            // show wait view here
            statusLabel.text = @"Processing...";
            break;

        case SKPaymentTransactionStatePurchased:

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            // remove wait view and unlock iClooud Syncing
            statusLabel.text = @"Done!";

            NSError *error = nil;
            [SFHFKeychainUtils storeUsername:@"IAPNoob01" andPassword:@"whatever" forServiceName: kStoredData updateExisting:YES error:&error];

            // apply purchase action  - hide lock overlay and
            [oStockLock setBackgroundImage:nil forState:UIControlStateNormal];

            // do other thing to enable the features

            break;

        case SKPaymentTransactionStateRestored:

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            // remove wait view here
            statusLabel.text = @"";
            break;

        case SKPaymentTransactionStateFailed:

            if (transaction.error.code != SKErrorPaymentCancelled) {
                NSLog(@"Error payment cancelled");
            }
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            // remove wait view here
            statusLabel.text = @"Purchase Error!";
            break;

        default:
            break;
    }

最后两种情况,加上默认情况,给了我以下错误:

无法从switch语句跳转到此case标签

我已经多次使用switch语句;这是我第一次看到这个.代码是从一个教程(here)中复制的,我正在try 将其改编为我的应用程序.谢谢你在这件事上的帮助.SD

推荐答案

C并不迅速.如果你在所有箱子的内部用花括号来组织你的switch条陈述,你会更开心,比如this条:

switch (tag) {
    case 1: { // curly braces
        // ...
        break;
    }
    case 2: {  // curly braces
        // ...
        break;
    }
    case 3: {  // curly braces
        // ...
        break;
    }
}

额外的花括号可以让你做一些你不能做的事情.

Objective-c相关问答推荐

iPhone:将日期字符串转换为相对时间戳

如何可靠地检测 iOS 9 上是否连接了外部键盘?

如何在 iOS Objective-C 头文件中将函数标记为已弃用?

在 Objective C 中动态调用类方法

保存 UIImage,以错误的方向加载它

如何在 Cocoa 中创建字符串的 MD5 哈希?

在我的 UIImageView 的子类中没有调用 drawRect

为 iphone 应用程序设置自动构建服务器的最佳实践?

在 NSData 和 base64 字符串之间转换

如何以编程方式暂停 NSTimer?

UIRefreshControl - 在 iOS 7 中 pull 刷新

通过 ObjC 类别覆盖方法并调用默认实现?

iOS 崩溃日志(log)中的异常类型

Objective-C 实例变量?

自定义 UINavigationBar 背景

Objective-C:块 vs. Select 器 vs. 协议

主队列上的 dispatch_sync 与 dispatch_async

使用单独的委托/数据源时的 UITableView 问题

UIPageViewController,如何在不打乱数据源指定顺序的情况下正确跳转到特定页面?

公开只读但具有私有设置器的 Objective-C 属性