我试图在按下按钮后从左侧获取UITableView幻灯片。进入主视图后,表格视图不应该可见。我也希望表视图占据屏幕空间的一部分,而不是整个屏幕,否则我会尝试制作一个单独的视图。如何让UI TableView从屏幕开始?
我曾尝试使用创建一个IBOutlet到的tableview和转移在viewWillAppear中(位置):
optionsTableView.center.x -= view.bounds.width
这没有工作,我想是因为约束系统的?
接着我试图具有在前缘和后空间的限制用作占位符,并且在viewDidLoad中()块中加入:
//Replace placeholder constraint with a constraint of less than or equal to 0
let leadingSpaceConstraint = NSLayoutConstraint(item: optionsTableView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.LessThanOrEqual, toItem: view, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0)
optionsTableView.addConstraint(leadingSpaceConstraint)
//Add Trailing space constraint
let trailingSpaceConstraint = NSLayoutConstraint(item: optionsTableView, attribute: NSLayoutAttribute.Trailing,relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0)
optionsTableView.addConstraint(trailingSpaceConstraint)
然而,这导致在加载视图
2015-08-28 09:00:58.638 ShotMaker[25585:1566797] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7fb033c48c30 H:|-(<=0)-[UITableView:0x7fb03506e800] (Names: '|':UIView:0x7fb033c56ca0)>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView(UIConstraintBasedLayout) _viewHierarchyUnpreparedForConstraint:] to debug.
2015-08-28 09:00:58.639 ShotMaker[25585:1566797] View hierarchy unprepared for constraint.
错误我不知道如何解决这个问题,所以任何帮助将不胜感激。或者如果你知道更好的方法来完成我想要做的事情,我很乐意听到它。 (容器视图?以编程的方式实现整个事物?巧妙的约束操作?) 另外,如果你知道为什么我第一次尝试移动视图的中心不起作用,那也是有用的信息。
最后,我还没有试图从左侧开始幻灯片放映,因为我刚刚从屏幕上开始挂断电话,但随时提供一个如何做到这一点的想法,因为我真的没有线索。
谢谢
P.S.这是我在堆栈交换中的第一个问题,所以如果我犯了任何格式错误,或者如果我可以提供更多信息以提供更多帮助,请让我知道。