我的平移手勢以編程方式假按鈕按下。如果按下實際的按鈕,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運行時,它會注意到該變量已更改,並將使用不同的值加載標題和表格。 –