PrepareForSegue mystery

前端 未结 3 1914
暖寄归人
暖寄归人 2021-01-28 13:47

I\'ve got a prepareForSegue method in two different VCs. One uses an if statement, while the other is intended to use a switch. The code is virtually i

3条回答
  •  Happy的楠姐
    2021-01-28 14:39

    In C/Objective-C, you cannot declare variables in a switch statement like that. If you want to declare variables for use in a specific case of a switch statement, you can put all the code for that case in a statement block:

    switch ([sender tag])
    {
        case aVsAButton_tag:
        {
            UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
            AvsAViewController *aVSaVC = (AvsAViewController *)navController.topViewController;
            aVSaVC.delegate = self;
            SearchSpecs *thisSpec = (SearchSpecs *)[SearchSpecs MR_createInContext:localContext];
            aVSaVC.currentSpec = thisSpec;
        }
            break;
    
        default:
            break;
    }
    

提交回复
热议问题