gpt4 book ai didi

ios - 代码 : Invalid redeclaration of 'ViewController'

转载 作者:可可西里 更新时间:2023-11-01 00:34:17 29 4
gpt4 key购买 nike

我刚刚完成我的应用程序并且它运行良好,但是在按文件 -> 复制后突然,我收到一条消息说

Invalid redeclaration of '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)

}

}

最佳答案

此错误意味着您声明了另一个文件:

class ViewController...

您可能更改了文件名,例如更改为 ViewControllerTwo.swift,但请确保也更改了类声明。

关于ios - 代码 : Invalid redeclaration of 'ViewController' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46842613/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com