我的平移手势以编程方式假按钮按下。如果按下实际的按钮,VC的viewDidLoad会再次运行一次,停止并很好。 但是当我使用泛手势以编程方式假按钮按下时,viewDidLoad运行约七次,然后停止。潘Segue调用viewDidLoad循环
右边手势会触发加载少数几次的“明天”状态。此时,左边手势会触发“今天”状态。这也加载4-5次。
任何想法?下面的一些代码,如果需要。
潘姿态加入viewDidLoad中:
//Adds edge gesture depending on VC state
if curMainList == "Today" {
let panLeftEdgeGesture_MainVC = UIScreenEdgePanGestureRecognizer(target: self, action: "panLeftEdge_toLifeList:")
panLeftEdgeGesture_MainVC.edges = .Left
view.addGestureRecognizer(panLeftEdgeGesture_MainVC)
let panRightEdgeGesture_MainVC = UIScreenEdgePanGestureRecognizer(target: self, action: "panFromRightEdgeAction:")
panRightEdgeGesture_MainVC.edges = .Right
view.addGestureRecognizer(panRightEdgeGesture_MainVC)
self.footer_LeftBtn.addTarget(self, action: "LeftFooterBtnPress", forControlEvents: UIControlEvents.TouchUpInside)
}
else {
let panLeftEdgeGesture = UIScreenEdgePanGestureRecognizer(target: self, action: "panFromLeftEdgeAction:")
panLeftEdgeGesture.edges = .Left
view.addGestureRecognizer(panLeftEdgeGesture)
}
手势的触发:
//Gestures visible when view is 'Today'
func panLeftEdge_toLifeList(sender: UIScreenEdgePanGestureRecognizer) {
dispatch_async(dispatch_get_main_queue()) {() -> Void in
self.performSegueWithIdentifier("segueToLifeLists", sender: nil)
}
}
func panFromRightEdgeAction(sender: UIScreenEdgePanGestureRecognizer) {
//self.tomHdrBtnPress(tomorrowHdr)
tomorrowHdr.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
}
//Gesture added when viewing 'Tomorrow' list
func panFromLeftEdgeAction(sender: UIScreenEdgePanGestureRecognizer) {
//self.todayHdrBtnPress(todayHdr)
todayHdr.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
}
@IBAction func todayHdrBtnPress(sender: AnyObject) {
UIView.animateWithDuration(0.75, animations: {
//Header changes
self.hdrBox.backgroundColor = UIColor(red: 46/255.0, green: 173/255.0, blue: 11/255.0, alpha: 1.0)
self.footer_RightArrow.hidden = false
self.footer_RightBtn.hidden = false
}
, completion: nil
)
curMainList = "TodayTask"
currentListEntity = curMainList
viewDidLoad()
}
@IBAction func tomHdrBtnPress(sender: AnyObject) {
UIView.animateWithDuration(0.75, animations: {
//Header changes
self.hdrBox.backgroundColor = UIColor(red: 49/255.0, green: 82/255.0, blue: 171/255.0, alpha: 1.0)
self.footer_LeftBtn.addTarget(self, action: "LeftFooterBtnPress", forControlEvents: UIControlEvents.TouchUpInside)
}
, completion: nil
)
curMainList = "TomTask"
currentListEntity = curMainList
viewDidLoad()
}
您不应该“以编程方式伪造按钮按下”。而且你不应该手动调用生命周期事件。你在很多方面都从根本上解决了这个问题。 – nhgrif
你究竟在做什么*试图*实际*做什么?需要重复调用'viewDidLoad'的是什么? – nhgrif
@nhgrif从用户的角度来看,平底锅正在触发一个新的页面。它实际上是标题标题和颜色改变的VC。但对用户来说,他们会觉得自己在刷卡切换页面。没有什么应该反复运行。看看它如何更新列表变量?当viewDidLoad运行时,它会注意到该变量已更改,并将使用不同的值加载标题和表格。 –