我刚刚完成了我的应用程序,它工作正常,但在按下文件后突然 - >重复,我有一条消息说
如果可以的话,请帮帮我吧?谢谢' ViewController'
的重新声明无效
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet var slideScrollView: UIScrollView!
@IBOutlet var pageControl: UIPageControl!
override func viewDidLoad() {
slideScrollView.delegate = self
let slides:[Slide] = createSlides()
setupSlideScrollView(slides: slides)
pageControl.numberOfPages = slides.count
pageControl.currentPage = 0
view.bringSubview(toFront: pageControl)
}
func createSlides () -> [Slide] {
let slide1: Slide = Bundle.main.loadNibNamed("Slide", owner:self, options:nil)?.first as!Slide
slide1.label.text = "Slide1"
let slide2: Slide = Bundle.main.loadNibNamed("Slide", owner:self, options:nil)?.first as!Slide
slide2.label.text = "Slide2"
return [slide1, slide2]
}
func setupSlideScrollView (slides:[Slide]) {
slideScrollView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
slideScrollView.contentSize = CGSize(width: view.frame.width * CGFloat(slides.count), height: view.frame.height)
slideScrollView.isPagingEnabled = true
for i in 0 ..< slides.count {
slides[i].frame = CGRect(x: view.frame.width * CGFloat(i), y: 0, width: view.frame.width, height: view.frame.height)
slideScrollView.addSubview(slides[i])
}
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let pageIndex = round(scrollView.contentOffset.x/view.frame.width)
pageControl.currentPage = Int(pageIndex)
}
}
答案 0 :(得分:4)
此错误表示您使用以下命令声明了另一个文件:
class ViewController...
您可能已更改了文件名,例如更改为ViewControllerTwo.swift,但请务必更改类声明。
答案 1 :(得分:1)
点击重复后,您是否按了保存?该消息已经告诉您一个解决方案。您需要找到名为ViewController
的其他类。
两个步骤可能会有所帮助:
ViewController
(搜索)