samedi 28 novembre 2015

Switch Statement and If Statement

Why switch case does not take multiple lines where if do work perfectly

if(indexPath.row == 1){
            UIViewController *viewController = [UIViewController new];
            viewController.view.backgroundColor = [UIColor whiteColor];
            viewController.title = _titlesArray[indexPath.row];
            [self.navigationController pushViewController:viewControlleranimated:YES];
}

same code unable to use in switch case statement

            switch (indexPath.row) {
                case 0:
                    UIViewController *viewController = [UIViewController new];
                    viewController.view.backgroundColor = [UIColor whiteColor];
                    viewController.title = _titlesArray[indexPath.row];
                     [self.navigationController pushViewController:viewControlleranimated:YES];
    break;
                    case 1:
                    break;

                    default
                     break:
}

In switch statement its gives an errors.... I forcibly using if else statement instated of switch case. Can any one advice me how use switch case statment.

Aucun commentaire:

Enregistrer un commentaire