如何从情节提要“Main”中修复,但没有获得 UITableView。代码
Posted
技术标签:
【中文标题】如何从情节提要“Main”中修复,但没有获得 UITableView。代码【英文标题】:How to fix from storyboard "Main", but didn't get a UITableView.' xcode 【发布时间】:2020-04-24 00:19:20 【问题描述】:我对 ios 编程非常陌生。 我正在从教程中运行一个简单的应用程序,当我尝试在模拟器(iPhone 11)上运行它时,它给了我以下错误消息
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-BYZ-38-t0r" from storyboard "Main", but didn't get a UITableView.'
AppDeligate
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let viewController = ViewController()
window?.rootViewController = UINavigationController(rootViewController: viewController)
return true
// MARK: UISceneSession Lifecycle
@available(iOS 13.0, *)
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
@available(iOS 13.0, *)
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>)
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
ViewController.swift
import UIKit
class ViewController: UITableViewController
override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view.
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Logout", style: .plain, target: self, action: #selector(handleLogout))
@objc
func handleLogout()
let loginController = LoginController()
self.navigationController?.pushViewController(loginController, animated: true)
这就是我的 Main.Storyboard 的样子
请问我该如何解决这个问题,我上网查看了,但由于我对 iOS 世界完全陌生,我无法解决它。
谢谢 回复
【问题讨论】:
【参考方案1】:用 UITableviewcontroller 替换您在主情节提要上看到的视图控制器。只需拖放表格视图控制器并将其作为初始视图控制器。
然后将 UItableviewcontroller 类添加到您的项目中。将场景 UITableview 控制器命名为与表视图控制器类名称相同。并且不要忘记将所有插座与视图控制器类连接起来。使用自定义类列右侧的侧边栏附加带有类名的情节提要场景。 
【讨论】:
【参考方案2】:崩溃意味着你使用的是普通的 vc 而不是 tableVC,你必须拖动它(hit command + shift + l)
这个样子
【讨论】:
【参考方案3】:尝试在此处解决此问题:
inplace : class ViewController: UITableViewController
use : class ViewController: UIViewController
【讨论】:
当我这样做并运行应用程序时,应用程序在手机上运行,但我只看到一个白屏 IN Storyboard 将你的控制器嵌入到导航控制器中 嗨,阿尼尔,真的很抱歉,我该怎么做 在您的 Storyboard 中,您可以通过选择 View Controller 然后从顶部的菜单中选择 Editor->Embed In->Navigation Controller 来将 ViewController 嵌入到 Navigation Controller 中。 嘿 Anil,我设法用 UITableViewController 对其进行了排序,非常感谢您的回复以上是关于如何从情节提要“Main”中修复,但没有获得 UITableView。代码的主要内容,如果未能解决你的问题,请参考以下文章