swift - 为什么我的 UIViewController 没有出现在弹出卡中?
问题描述
我想为我的一个UIViewController创建一个弹出窗口,并在 GitHub 上找到了这个repo 。
它与我的只有 4 个UILabel的InfoViewController一起工作正常(我认为这可能是当你使用可重复使用的单元格时它没有显示的问题)但不知何故它不适用于我的StructureNavigationListViewController,我不知道为什么。
我在MainViewController中调用了didTapCategory方法,其中应该弹出 StructureNavigationController 但我只看到变暗视图(这很奇怪,因为点击识别器和平移手势工作正常,但没有显示内容)
在我的MainViewController中,我像以前一样设置了弹出窗口:
@IBAction func didTapCategory(_ sender: UIBarButtonItem) {
let popupContent = StructureNavigationListViewController.create()
let cardpopUp = SBCardPopupViewController(contentViewController: popupContent)
cardpopUp.show(onViewController: self)
}
在我的StructureNavigationListViewController中,我设置了表格视图并弹出:
public var popupViewController: SBCardPopupViewController?
public var allowsTapToDismissPopupCard: Bool = true
public var allowsSwipeToDismissPopupCard: Bool = true
static func create() -> UIViewController {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "StructureNavigationListViewController") as! StructureNavigationListViewController
return vc
}
@IBOutlet var tableView: UITableView!
var structures = Variable<[Structure]>([])
public var treeSource: StructureTreeSource?
let disposeBag = DisposeBag()
var depthDictionary : [String : Int] = [:]
public override func viewDidLoad() {
structures.asObservable()
.bind(to:tableView.rx.items) {(tableView, row, structure) in
let cell = tableView.dequeueReusableCell(withIdentifier: "StructureNavigationCell", for: IndexPath(row: row, section: 0)) as! StructureNavigationCell
cell.structureLabel.text = structure.name
cell.spacingViewWidthConstraint.constant = 20 * CGFloat(self.depthDictionary[structure.id]!)
return cell
}.disposed(by:disposeBag)
_ = tableView.rx.modelSelected(Structure.self).subscribe(onNext: { structure in
let storyBoard = UIStoryboard(name:"Main", bundle:nil)
let plansViewCtrl = storyBoard.instantiateViewController(withIdentifier: "PlansViewController2") as! PlansViewController2
self.treeSource?.select(structure)
plansViewCtrl.treeSource = self.treeSource
plansViewCtrl.navigationItem.title = structure.name
self.show(plansViewCtrl, sender: self)
if let mainVC = self.parent as? ProjectOverViewTabController2 {
mainVC.addChildView(viewController: plansViewCtrl, in: mainVC.scrollView)
}
})
showList()
}
func showList() {
if treeSource == nil {
treeSource = StructureTreeSource(projectId:GlobalState.selectedProjectId!)
}
//The following piece of code achieves the correct order of structures and their substructures.
//It is extremely bad designed and rather expensive with lots of structures and should
//therefore be refactored!
if let strctrs = getStructures() {
var sortedStructures : [Structure] = []
while(sortedStructures.count != strctrs.count) {
for strct in strctrs {
if let _ = sortedStructures.index(of: strct) {
continue
} else {
depthDictionary[strct.id] = getDepthOfNode(structure: strct, depth: 1)
if let structures = getStructures() {
if let parent = structures.first(where: {$0.id == strct.parentId}) {
if let index = sortedStructures.index(of: parent) {
sortedStructures.insert(strct, at: index+1)
}
} else {
sortedStructures.insert(strct, at: 0)
}
}
}
}
}
structures.value = sortedStructures
tableView.reloadData()
}
}
func getDepthOfNode(structure: Structure, depth: Int) -> Int {
if(structure.parentId == nil || structure.parentId == "") {
return depth
} else {
if let structures = getStructures() {
if let parent = structures.first(where: {$0.id == structure.parentId}) {
return getDepthOfNode(structure: parent, depth: depth + 1)
}
}
}
return -1
}
private func getStructures() -> Results<Structure>? {
do {
if let projectId = GlobalState.selectedProjectId {
return try Structure.db.by(projectId: projectId)
}
} catch { Log.db.error(error: error) }
return nil
}
}
这里有很多代码。对不起..
是因为我在viewDidLoad()将单元格出列之后调用了create()方法吗?
解决方案
很难说是什么问题,因为你没有留下关于didTapCategory
应该在哪里调用的信息,但也许这与你的modelSelected
订阅过早发布有关?
编辑:如此 处发布:https ://stackoverflow.com/a/28896452/11851832如果您的自定义单元是使用 Interface Builder 构建的,那么您应该注册 Nib,而不是类:
tableView.registerNib(UINib(nibName: "CustomCell", bundle: nil), forCellReuseIdentifier: "CustomCellIdentifier")
推荐阅读
- kubernetes - 同时运行两个 Kubernetes 仪表板
- assembly - 如何在 2 列中显示交替的文本行?
- sql-server - 两个表的多内连接
- r - 无法获取带有边界框的谷歌卫星图像
- reactjs - 使用 jest 和酶进行测试时,在单击事件中不调用模拟函数
- typescript - 如何推断对象属性的类型
- android - BottomSheetDialogFragment 通过 android 软键(返回、主页)进行动画处理
- email - BUILD_LOG 电子邮件输出不包括控制台日志中的错误文本
- typescript - 如何构建 monorepo 依赖项?
- python - 可散列和不可变之间有什么区别?