此刻学习swift,任何帮助都会受到赞赏 - 将代码从swift 3更新为swift 4 - 在构建时出现以下错误:
参数标签'(_:,viewControllerAfterViewController:)'不匹配任何可用的重载
我认为与此错误相关的代码位于以下goToNextVC函数中:
<?php
include 'db.php';
$sql = $db->query("SELECT * FROM employee");
$res = mysqli_fetch_assoc($sql);
echo 'name:"'.$res['name'].'", salary: "'.$res['salary'].'"';
?>
完整代码:
func goToNextVC() {
let nextVC = pageViewController(self, viewControllerAfterViewController: viewControllers![0] )!
setViewControllers([nextVC], direction: .Forward, animated: true, completion: nil)
}
extension ViewController: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
// navigate right
switch viewController {
case cardsVC:
return profileVC
case profileVC:
return nil
case matchesVC:
return cardsVC
default:
return nil
}
}
}
答案 0 :(得分:0)
此:
let nextVC = pageViewController(self, viewControllerAfterViewController: viewControllers![0] )!
需要:
let nextVC = pageViewController(self, viewControllerAfter: viewControllers![0] )!
当你在它时,你需要摆脱强制解包(!
)。 pageViewController(_:viewControllerAfter:)
可以返回nil
,使用!
会导致您的应用崩溃。
func goToNextVC() {
if let viewControllers = viewControllers {
if let nextVC = pageViewController(self, viewControllerAfter: viewControllers[0]) {
setViewControllers([nextVC], direction: .Forward, animated: true, completion: nil)
}
}
}