簡體   English   中英

XCode 8.3.2 Storyboard UI元素不會出現在模擬器中

[英]XCode 8.3.2 Storyboard UI elements won't appear in simulator

免責聲明:我發現了許多這樣的問題,但沒有一個有幫助。

就像標題所說的那樣,我的CarDetailViewController的情節提要UI元素不會出現在模擬器中,但是會出現在項目中的其他視圖控制器中。

有問題的vc

總體項目

碼:

import UIKit
import EventKit
import CoreData


class CarDetailViewController: UIViewController, 
UIImagePickerControllerDelegate, UINavigationControllerDelegate, 
NSFetchedResultsControllerDelegate {


/* -------------------------------------------------------------------------------------------------------- */
let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

/* -------------------------------------------------------------------------------------------------------- */

@IBOutlet weak var myImageView: UIImageView!
let picker = UIImagePickerController()
@IBOutlet weak var carLabel: UILabel!

@IBAction func photoFromLibrary(_ sender: UIButton) {
    picker.allowsEditing = false
    picker.sourceType = .photoLibrary
    picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
    present(picker, animated: true, completion: nil)

}

override func viewDidLoad() {
    super.viewDidLoad()
    picker.delegate = self
    self.view = UIImageView(image: UIImage(named: "Landing.png"))
    // Do any additional setup after loading the view.

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@nonobjc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: AnyObject])
{
    let chosenImage = info[UIImagePickerControllerOriginalImage]
    myImageView.contentMode = .scaleAspectFit //3
    myImageView.image = chosenImage as? UIImage //4
    dismiss(animated: true, completion: nil) //5
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController)
{
    dismiss(animated: true, completion: nil)
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

嘗試這個 :

刪除此行:

self.view = UIImageView(image: UIImage(named: "Landing.png"))

您需要將背景圖片設置為

  self.view.backgroundColor = UIColor(patternImage: UIImage(named:"Landing.png")!)

您不將圖像視圖分配給uiview,所以代替

self.view = UIImageView(image: UIImage(named: "Landing.png"))

您有以下選擇:

  1. 您應該將uiimageview添加到uiview中並為其分配該圖像。
  2. 您可以使用此圖像創建漸變背景色。

恕我直言,使用第一種方法,因為第二種可能會導致不同設備的分辨率問題

編輯更新:而不是按以下方式初始化vc

let destination = CarDetailViewController() // Your destination

嘗試做以下

let storyboard = UIStoryboard(name: <Storyboard-name>, bundle: nil)
let inquireViewController = storyboard.instantiateViewController(withIdentifier: String(describing:CarDetailViewController.self)) as! CarDetailViewController

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM