Home > Net >  Presenting Full Screen Programmatically
Presenting Full Screen Programmatically

Time:11-11

I am presenting views from a switch statement as seen in the code. What code would i add to present each view in full screen. I have tried a few methods with self, but nothing changes. I have also tried setting the screen from auto to full screen in storyboard. Any ideas??

         func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
             tableView.deselectRow(at: indexPath, animated: true)
                 let settingsSection = SettingsSection(rawValue: indexPath.section)
                 switch settingsSection {
                 case .social:
                     let value = SocialOptions(rawValue: indexPath.row)
                     switch value {
                     case .editProfile:
                         present(editProfileVC, animated: true) {
                             
                         }
                     case .changePassword:
                         present(changePasswordVC, animated: true) {
                             
                         }
                     case .deleteAccount:
                         present(deleteVC, animated: true) {
                             
                         }
                     default:
                         debugPrint("Invalid Selection")
                             
                         }
                     
                 case .communications:
                     let value = CommunicationOptions(rawValue: indexPath.row)
                     switch value {
                     case .notifications:
                         present(notificationVC, animated: true) {
                             
                         }
                     case .language:
                         present(languageVC, animated: true) {
                             
                         }
                     case .contactUs:
                         present(contactVC, animated: true) {
                            
                             
                         }

                     default:
                         debugPrint("Invalid selection")
                     }
                 default:
                     debugPrint("Invalid selection")
                 }
             }
             
 }

CodePudding user response:

Embed your ViewControllers in a UINavigationController. You can set UINavigationController().navigationBar.isHidden = true if you don't want the nav bar at the top. The code you want is UIViewController().modalPresentationStyle = .fullScreen.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
    let settingsSection = SettingsSection(rawValue: indexPath.section)
    
    var vc: UIViewController?
    var navController: UINavigationController!
    
    switch settingsSection {
    case .social:
        let value = SocialOptions(rawValue: indexPath.row)
        switch value {
        case .editProfile:      vc = editProfileVC
        case .changePassword:   vc = changePasswordVC
        case .deleteAccount:    vc = deleteVC
        default:    debugPrint("Invalid Selection")
        }
    case .communications:
        let value = CommunicationOptions(rawValue: indexPath.row)
        switch value {
        case .notifications:    vc = notificationVC
        case .language:         vc = languageVC
        case .contactUs:        vc = contactVC
        default:    debugPrint("Invalid selection")
        }
    default:    debugPrint("Invalid selection")
    }
    
    if let vc = vc {
        navController = UINavigationController(rootViewController: vc)
        navController.modalPresentationStyle = .fullScreen
        self.present(navController, animated: true)
    }
    
}
  • Related