【发布时间】:2015-07-24 03:52:15
【问题描述】:
在我的主视图控制器中,我有一个 MKMapView 和 TableView。 tableview 使用 AlamoFire 调用用户信息 API 来填充其单元格。
我希望发生的事情: 当您选择一个单元格时,带有更详细用户信息的第二个容器视图将进入 tableview 所在的屏幕部分。同时,地图视图将使用该用户的位置进行注释。
问题: 当单元格被选中时,第二个容器视图滑到屏幕上(好),地图注释(好),但随后信息容器视图再次消失(坏)。再次点击最初选择的单元格,信息容器视图会滑回屏幕上以保持不变。我需要摆脱这种双击。
地图注释似乎出于某种原因否定了这个过程。当我注释掉地图注释时,VC 转换工作正常……只需轻轻一按。
任何想法都会有所帮助。
这是有问题的代码:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.localTableView.deselectRowAtIndexPath(indexPath, animated: true)
dispatch_async(dispatch_get_main_queue(),{
self.populateInfoContainerView(indexPath.row)
self.mapView.selectAnnotation(self.users[indexPath.row], animated: true)
if(self.userInfoContainerView.frame.origin.x == UIScreen.mainScreen().bounds.size.width){
self.showInfoView(true)
} else {
self.hideInfoView(true)
}
})
}
func showInfoView(animated: Bool){
UIView.animateWithDuration(0.33, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 1.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: ({
self.userInfoContainerView.frame.origin.x = 0
self.localTableView.frame.origin.x = -UIScreen.mainScreen().bounds.size.width
}), completion: { finished in
//animation complete
})
self.infoVisible = true
}
func hideInfoView(animated: Bool){
let xPos = UIScreen.mainScreen().bounds.size.width
if(animated == true){
UIView.animateWithDuration(0.25, animations: ({
self.userInfoContainerView.frame.origin.x = xPos
self.localTableView.frame.origin.x = 0
}), completion: { finished in
//animation complete
})
} else {
self.userInfoContainerView.frame.origin.x = xPos
}
self.infoVisible = false
}
谢谢。
【问题讨论】:
标签: ios swift uitableview mkmapview segue