サブビューを追加するときにこのエラーが発生しました。あなたは、エラーが現れるコードを見ることができます。私は プログラミングに比較的新しいので、私は助けが必要です。私はスウィフトでストーリーボードを使わずに書いています。 backgroundColor = UIColor.blueColorを()タイプ '(MapViewController).Type'(別名 'MapViewController.Type')の値を予想される引数タイプ 'UIView'に変換できません
編集:私は、エラーを引き起こしているかを知ることを言及するのを忘れてきた私が書いたところ
は無視します。 MapViewControllerはUIViewControllerであり、UIViewに配置しています。しかし、私は解決方法を知らない。私が欲しいもの
はここmapview
import UIKit
import MapKit
class MapCell1: MapCell, MKMapViewDelegate {
override func setupViews() {
backgroundColor = UIColor.blueColor()
addSubview(MapViewController) //Cannot convert value of type '(MapViewController).Type' (aka 'MapViewController.Type') to expected argument type 'UIView'
}
}
import UIKit
import MapKit
class MapViewController: UIViewController {
var window: UIWindow?
var mapView: MKMapView?
override func viewDidLoad() {
super.viewDidLoad()
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.view.backgroundColor = UIColor.whiteColor()
self.mapView = MKMapView(frame: CGRectMake(0, 20, (self.window?.frame.width)!, 300))
self.view.addSubview(self.mapView!)
}
}
を追加することですMapCellためのコードです:
追加しようとしているているためimport UIKit
class MapCell: BaseCell, UICollectionViewDelegate {
let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
cv.backgroundColor = UIColor.redColor()
return cv
}()
let cellId = "cellId"
override func setupViews() {
super.setupViews()
addSubview(collectionView)
addconstraintsWithFormat("H:|[v0]|", views: collectionView)
addconstraintsWithFormat("V:|[v0]|", views: collectionView)
}
}
And BaseCell:
mport UIKit
class BaseCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
func setupViews() {
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
class BaseCell: UICollectionViewCell {
func setupViews() {
}
}
}
を使用したくない理由として興味MapViewControllerは、ビューコントローラ..ですあなたはそれをビューに追加しようとしています...それがあなたがしようとしているものかどうかわかりません。 – penatheboss
ええ、それは私がやろうとしていることです。 – Stc
ビューコントローラをビューに追加することはできません。ビューまたはビューへのビューをビューコントローラに追加することができます – penatheboss