我有一个关于最初在 UISplitView 中加载辅助视图的快速问题。我目前在我的 masterVC.swift 中有代码,如果有的话,用数组中的第一个对象填充 detailsVC。这很好用,问题是当数组为空时,我可以预见地得到fatal error: unexpectedly found nil while unwrapping an Optional value
.
所以我的问题是,当没有对象时,我如何设置一个单独的“没有对象发现”样式的屏幕来回退?
谢谢,这是我的 MasterVC viewDidLoad 中的代码
let initialIndexPath = NSIndexPath(forRow: 0, inSection: 0)
if objects.count != 0 {
self.tableView.selectRowAtIndexPath(initialIndexPath, animated: true, scrollPosition:UITableViewScrollPosition.None)
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
self.performSegueWithIdentifier("showDetailsSegue", sender: initialIndexPath)
}
} else {
// I'm guessing the code would go here.
}