请参见下面的代码。 首先,我想说我是swift和xcode的新手。
我正在尝试使用此处的以下代码片段创建序列:
UA-xxxxxxx-4
不幸的是,我遇到一个错误:线程1:在下面的AppDelegate上发出SIGABRT信号
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if(indexPath.section == 0) {
if(indexPath.row == 3) {
dismiss(animated: true, completion: nil)
self.performSegue(withIdentifier: "warehouse", sender: self)
}
}
}
我已经搜索了此错误代码,它似乎与丢失或错误代码有关。而且由于我是新手,所以我无法弄清自己的缺失。 下面是tableView的整个代码段,我希望从中执行选择到新的视图控制器
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
guard let splitViewController = window!.rootViewController as? UISplitViewController,
let leftNavController = splitViewController.viewControllers.first as? UINavigationController,
let masterViewController = leftNavController.topViewController as? MasterVC,
let detailViewController = splitViewController.viewControllers.last as? DetailVC
else { fatalError() }
let firstMail = masterViewController.mail.first
detailViewController.mails = firstMail
masterViewController.delegate = detailViewController
masterViewController.navigationItem.leftItemsSupplementBackButton = true
detailViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
UISearchBar.appearance().tintColor = .blue
UINavigationBar.appearance().tintColor = .blue
splitViewController.preferredDisplayMode = .automatic
splitViewController.delegate = self
return true
}
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
guard let secondaryAsNavController = secondaryViewController as? UINavigationController else {return false}
guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailVC else {return false}
if topAsDetailController.detailMail == nil {
return true
}
return false
}
}
编辑----
抱歉,这是我忘记显示的日志。
import UIKit
class SideMenuTable: UITableViewController {
var menu = [Menu]()
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Change Menu View"
menu = [
Menu(title: "Main"),
Menu(title: "Departments"),
Menu(title: "Deliveries"),
Menu(title: "Warehouse"),
Menu(title: "Help")
]
}
override func viewWillAppear(_ animated: Bool) {
if tableView.isHidden {
if let selectionIndexPath = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: selectionIndexPath, animated: animated)
}
} else if tableView.isFocused {
if let selectionIndexPaths = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: selectionIndexPaths, animated: animated)
}
}
super.viewWillAppear(animated)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 5
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "sideCell", for: indexPath)
let menuSide: Menu
menuSide = menu[indexPath.row]
cell.textLabel!.text = menuSide.title
cell.textLabel?.textAlignment = .center
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Warehouse" {
performSegue(withIdentifier: "Warehouse", sender: self)
}
}
答案 0 :(得分:1)
错误消息很清楚:
从情节提要“ Main”中实例化了具有标识符“ UIViewController-gFD-aE-X8s”的视图控制器,但未获得UITableView。
因此,情节提要中此视图控制器的配置有问题。它应该是一个UITableViewController,但显然不是,或者很可能是(很可能),您已经不小心解开了从视图控制器运行到表视图的View出口,并将其连接到其他东西。
答案 1 :(得分:-1)
仅此递归调用
performSegue(withIdentifier: "Warehouse", sender: self)
在此处的prepareForSegue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Warehouse" {
performSegue(withIdentifier: "Warehouse", sender: self)
}
}