Cha*_*lva 6 uitabbarcontroller ios swift
我想使用滑动手势在标签栏控制器之间导航,同时保留默认标签栏.我使用此代码但显示错误.
import UIKit
 class FirstViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        var leftSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
        leftSwipe.direction = .Left
        view.addGestureRecognizer(leftSwipe)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
        func handleSwipes(sender:UISwipeGestureRecognizer) {
            if (sender.direction == .Left) {
                let storyboard = UIStoryboard(name: "Main", bundle: nil)
                let vc = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as! UIViewController
                self.presentViewController(vc, animated: false, completion: nil)
            }
            if (sender.direction == .Right) {
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)
    您的函数handleSwipes必须是类级别函数,而不是另一个函数的内部函数:
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
    // remove the func from here
}
func handleSwipes(sender:UISwipeGestureRecognizer) {
    if (sender.direction == .Left) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as! UIViewController
        self.presentViewController(vc, animated: false, completion: nil)
    }
    if (sender.direction == .Right) {
    }
}
Run Code Online (Sandbox Code Playgroud)
这是我看到的明显错误。您应该始终将错误消息与您的问题一起发布,以提高答案的质量。
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           7371 次  |  
        
|   最近记录:  |