在Swift中,我目前在我的第一個視圖控制器中有以下代碼,但是當我刷卡沒有任何反應?我的代碼有什麼問題?我必須執行其他的事情嗎?非常感謝SO用戶,非常感謝。swift之間在視圖控制器之間滑動
import UIKit
class ViewController: UIViewController, UIPageViewControllerDataSource {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var myViewControllers = Array(count: 4, repeatedValue:UIViewController())
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
let pvc = segue.destinationViewController as UIPageViewController
pvc.dataSource = self
let storyboard = UIStoryboard(name: "Main", bundle: nil);
var vc0 = storyboard.instantiateViewControllerWithIdentifier("FirstViewController") as UIViewController
var vc1 = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as UIViewController
var vc2 = storyboard.instantiateViewControllerWithIdentifier("ThirdViewController") as UIViewController
var vc3 = storyboard.instantiateViewControllerWithIdentifier("FourthViewController") as UIViewController
self.myViewControllers = [vc0, vc1, vc2, vc3]
pvc.setViewControllers([myViewControllers[1]], direction:.Forward, animated:false, completion:nil)
println("Loaded")
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
var currentIndex = find(self.myViewControllers, viewController)!+1
if currentIndex >= self.myViewControllers.count {
return nil
}
return self.myViewControllers[currentIndex]
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
var currentIndex = find(self.myViewControllers, viewController)!-1
if currentIndex < 0 {
return nil
}
return self.myViewControllers[currentIndex]
}
}
當你從左向右滑動時,它是否可以跨VC使用?我所做的只是將代碼粘貼到我的第一個VC中,儘管應該有更多我必須做的事情。我有一個UIPageViewController,但它具體必須被識別並以某種方式鏈接?我所做的只是粘貼代碼,並期望它從左向右滑動。此外,我不想使用按鈕/標籤繼續,只是輕掃。 – wogwog 2015-04-03 22:41:40
我畫了我的故事板。更清楚了嗎? – emrys57 2015-04-04 08:24:16
哦,我的工作!謝謝,雖然,當涉及到我的表格視圖,用戶必須在該行上滑動選項時,當我滑過它時,VC更改而不是tableview行選項。我可以重寫這個嗎? – wogwog 2015-04-05 00:55:35