Ios Swift:UITableView单元格在使用UIView.animateWithDuration时消失
我正在以编程方式将UITableView添加为视图的子视图,该视图使用UIView.animateWithDuration在按钮从单点单击到整个窗口时展开视图。基本上,一个以点为起点并通过动画扩展到全尺寸的长方体。我很难让表格填充单元格。起初,正在创建一个单元,但在动画完成后会很快消失,在对其进行播放后,我已使该单元在动画完成后保持不变,但现在当我点击该单元时,该单元消失。我不明白这里发生了什么。有人能帮忙吗 这是我的密码。注意,我已经删除了我认为与此问题无关的内容,以使代码更易于阅读Ios Swift:UITableView单元格在使用UIView.animateWithDuration时消失,ios,swift,uitableview,animatewithduration,Ios,Swift,Uitableview,Animatewithduration,我正在以编程方式将UITableView添加为视图的子视图,该视图使用UIView.animateWithDuration在按钮从单点单击到整个窗口时展开视图。基本上,一个以点为起点并通过动画扩展到全尺寸的长方体。我很难让表格填充单元格。起初,正在创建一个单元,但在动画完成后会很快消失,在对其进行播放后,我已使该单元在动画完成后保持不变,但现在当我点击该单元时,该单元消失。我不明白这里发生了什么。有人能帮忙吗 这是我的密码。注意,我已经删除了我认为与此问题无关的内容,以使代码更易于阅读 clas
class PokerLogSelectionView: UIViewController {
let logSelectionTableViewController = LogSelectionTableViewController()
let logSelectionTableView = UITableView()
// Irrelevant class variables removed
init(btn : PokerLogSelectionButton){
// Irrelevant view initialization code removed
// Display the subviews
self.displayLogListScrollView()
}
func displayLogListScrollView() {
// Frame is set to (0,0,0,0)
let frame = CGRect(x: self.subviewClosed, y: self.subviewClosed, width: self.subviewClosed, height: self.subviewClosed)
logSelectionTableView.delegate = self.logSelectionTableViewController
logSelectionTableView.dataSource = self.logSelectionTableViewController
// Set the frame of the table view
logSelectionTableView.frame = frame
// Give it rounded edges
logSelectionTableView.layer.cornerRadius = 10
// Remove the cell divider lines
logSelectionTableView.separatorStyle = UITableViewCellSeparatorStyle.None
logSelectionTableView.backgroundColor = logSelectionViewContentScrollViewColor
self.view.addSubview(logSelectionTableView)
//self.logSelectionTableView.reloadData()
//self.addChildViewController(logSelectionTableViewController)
}
override func viewDidAppear(animated: Bool) {
// Create animation
let timeInterval : NSTimeInterval = 0.5
let delay : NSTimeInterval = 0
UIView.animateWithDuration(timeInterval, delay: delay, options: UIViewAnimationOptions.CurveEaseOut, animations: {
// Irrelevant code removed
// Set the size and position of the view and subviews after the animation is complete
self.view.frame = CGRect(x: self.frameXopen, y: self.frameYopen, width: self.frameWopen, height: self.frameHopen)
self.logSelectionTableView.frame = CGRect(x: self.subviewXopen, y: self.svYopen, width: self.subviewWopen, height: self.svHopen)
}, completion: { finished in
self.addChildViewController(self.logSelectionTableViewController)
})
}
}
class LogSelectionTableViewController : UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(LogSelectionCell.self, forCellReuseIdentifier: "logCell")
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return pokerLibrary.logNames.count
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 20
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Selected row: \(indexPath.row)")
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell : LogSelectionCell = self.tableView.dequeueReusableCellWithIdentifier("logCell") as? LogSelectionCell {
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.textLabel!.text = pokerLibrary.logNames[indexPath.row].name
return cell
}
fatalError("Could not dequeue cell of type 'LogSelectionCell'")
}
}
注意:动画完成后,我可以看到tableview。颜色与背景视图中的视图不同,tableview不会消失,只是单元格。我希望有1个单元格,我已经打印出第0节中的行数,它总是返回1
谢谢你的帮助
编辑:
下面是单元格消失前视图层次结构的屏幕截图。
这是点击单元格后视图层次结构的屏幕截图,它消失了。
我在自定义单元格中重写了touchesbearth方法,并且没有调用它的超类方法。当我点击单元格时,它停止消失,但当我滚动tableView时,它仍然消失。请提供更多信息。运行时使用Xcode中的视图检查器告诉我们单元格是否消失或不可见,以及tableview的任何属性。抱歉,我仍在学习swift和Xcode。该单元在我点击它之前出现在视图层次结构中,一旦我点击它,它就会消失,因此我假设该单元已经消失。还有别的办法吗?tableview与上面代码中设置的一样。我应该注意,当我点击单元格时,我甚至不知道调用了什么代码。正如您在上面的代码中所看到的,我在didSelectRowAtIndexPath方法中放入了一个print语句,但是当我点击单元格时,它不会打印到控制台。除非数据源方法发生更改,否则单元格不会消失。TableView可能正在消失?您是否设置了背景颜色或在tableview中添加了页脚视图以测试它是否存在。拍摄视图检查器的屏幕截图也会有所帮助。(pre/post)我确实为tableview设置了背景色,并且它在前后都保持原样。我不完全确定你所说的视图检查器是什么意思。请提供更多信息。运行时使用Xcode中的视图检查器告诉我们单元格是否消失或不可见,以及tableview的任何属性。抱歉,我仍在学习swift和Xcode。该单元在我点击它之前出现在视图层次结构中,一旦我点击它,它就会消失,因此我假设该单元已经消失。还有别的办法吗?tableview与上面代码中设置的一样。我应该注意,当我点击单元格时,我甚至不知道调用了什么代码。正如您在上面的代码中所看到的,我在didSelectRowAtIndexPath方法中放入了一个print语句,但是当我点击单元格时,它不会打印到控制台。除非数据源方法发生更改,否则单元格不会消失。TableView可能正在消失?您是否设置了背景颜色或在tableview中添加了页脚视图以测试它是否存在。拍摄视图检查器的屏幕截图也会有所帮助。(pre/post)我确实为tableview设置了背景色,并且它在前后都保持原样。我不太清楚你所说的视图检查器是什么意思。