造成这种情况的原因:无法从 switch 语句跳转到此 case 标签
What is causing this: Cannot jump from switch statement to this case label
这是一个 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;
}
最后两种情况,加上默认情况,给我以下错误:
Cannot jump from switch statement to this case label
switch 语句我已经用了很多很多次了;这是我第一次看到这个。代码是从教程 (here) 复制而来的,我正在尝试将其改编为我的应用程序。将不胜感激这方面的帮助。标准差
C 不是 Swift。如果您在所有案例内部使用花括号构建 switch
语句,您会更快乐,例如 this:
switch (tag) {
case 1: { // curly braces
// ...
break;
}
case 2: { // curly braces
// ...
break;
}
case 3: { // curly braces
// ...
break;
}
}
额外的花括号级别让您可以做其他方式做不到的事情。
这是一个 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;
}
最后两种情况,加上默认情况,给我以下错误:
Cannot jump from switch statement to this case label
switch 语句我已经用了很多很多次了;这是我第一次看到这个。代码是从教程 (here) 复制而来的,我正在尝试将其改编为我的应用程序。将不胜感激这方面的帮助。标准差
C 不是 Swift。如果您在所有案例内部使用花括号构建 switch
语句,您会更快乐,例如 this:
switch (tag) {
case 1: { // curly braces
// ...
break;
}
case 2: { // curly braces
// ...
break;
}
case 3: { // curly braces
// ...
break;
}
}
额外的花括号级别让您可以做其他方式做不到的事情。