swift - 类型 'SecondPageController' 的值没有成员 'miniView'

标签 swift xcode

我得到的问题看起来很相似但又有点不同。 这是关于声明大小的问题,但这里有小错误。

我认为错误与 Main.stroyboard 有关,并尝试更改 ViewController 名称并将“miniView”添加到 ViewController。 我的错误是

“‘SecondPageController’类型的值没有成员‘miniView’”,

女巫是很常见的错误(我用这种格式看了很多相同的问题),但我认为我的错误与添加一些新 View 或其他东西有关。

这是我的代码。

class SecondPageController: UIViewController {



@IBOutlet weak var mainScrollView: UIScrollView!

var imageArray = [UIImage]()

var currentPage = 0

override func viewDidLoad() {
super.viewDidLoad()

imageArray = [UIImage(named: "bus1")!, UIImage(named: "bus2")!]

for i in 0..<imageArray.count {

let imageView = UIImageView()
imageView.image = imageArray[i]
imageView.contentMode = .scaleAspectFit
let xPosition = self.miniView.frame.width * CGFloat(i)
imageView.frame = CGRect(x: xPosition, y: 0, width: self.mainScrollView.frame.width, height: self.mainScrollView.frame.height)

mainScrollView.contentSize.width = mainScrollView.frame.width * CGFloat(i + 1)
mainScrollView.addSubview(imageView)

}

Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(startAnimating), userInfo: nil, repeats: true)
}

@objc func startAnimating() {

//that line check if the current page is the last one, and set it to the first, otherwise, it increment the currentPage
self.currentPage = (self.currentPage == imageArray.count-1) ? 0 : self.currentPage+1


var newOffset = mainScrollView.contentOffset
newOffset.x = mainScrollView.frame.width * CGFloat(self.currentPage)

self.mainScrollView.setContentOffset(newOffset, animated: true)
}

}

我期待为这个错误解决添加一些东西。

最佳答案

SecondPageController 中没有成员miniView。错误非常精确。

如果你想使用一个名为 miniView 的组件,你需要一个对它的引用,你可以使用两种方法:

1 - Storyboard:

将 View 拖到您的 UIViewController 并将其链接到 @IBOutlet weak var miniView: UIView!


2 - 程序化:

像这样实例化它:let miniView = UIView()


由于您使用的是 Storyboard,您可能忘记将 @IBOutlet 添加到该 View ,因此请使用方法 1。

关于swift - 类型 'SecondPageController' 的值没有成员 'miniView',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54641280/

相关文章:

ios - Swift 将字典数组传递给 NSMutableArray

ios - 如何通过以编程方式创建 UIImage 来更改 UITabBar 顶部边框的颜色?

ios - ALAssetsGroup numberOfAssets 在使用照片升级的 iPhone 上使用照片库返回 0

swift - 在类声明 Swift 中从其他矩阵变量创建矩阵实例变量

iphone - 用于选择器 View iPhone 的 JSON 数组

ios - 删除特定 pod 中已弃用的 iOS 框架警告

objective-c - 如何声明仅调试语句

ios - Swift 项目中体系结构的 undefined symbol

iphone - 我的应用崩溃了,但在iPhone SDK上却没有显示错误Xcode

xcode - 使用clang++ 4.2时,“选择的构造函数在复制初始化错误中是显式的”