Код: Выделить всё
ContentView.swiftКод: Выделить всё
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Create a UIWindow instance
window = UIWindow(frame: UIScreen.main.bounds)
if window == nil {
print("Window is nil.")
} else {
print("Window is not nil.")
}
let viewController = ViewController()
window?.rootViewController = viewController
window?.makeKeyAndVisible()
if window?.rootViewController == nil {
print("Root view controller is not set.")
} else {
print("Root view controller is set.")
}
if let rootView = window?.rootViewController?.view {
print("Root view hierarchy:")
print(rootView.subviews)
}
if let viewController = window?.rootViewController as? ViewController {
print("Status label text: \(viewController.statusLabel.text ?? "Not set")")
}
return true
}
}
Код: Выделить всё
testApp.swiftКод: Выделить всё
import UIKit
class ViewController: UIViewController {
public var statusLabel = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
// Configure status label
statusLabel.text = "This is an example"
statusLabel.textAlignment = .center
statusLabel.numberOfLines = 0
statusLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(statusLabel)
NSLayoutConstraint.activate([
statusLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
statusLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
}
}
Кто-нибудь может сообщить мне, в чем здесь проблема? СтатусLabel инициализирован неправильно? Я также вижу сообщение [EventDispatcher] Не найдено UIEvent для события поддержки типа: 3 в журнале.
Заранее спасибо
P.S: я использую xcode 15.0.1, целевой iPhone, SDK iOS, минимальные развертывания 16.0, поле «Исключенные архитектуры» пусто. Пожалуйста, дайте мне знать, если я что-то пропустил
Подробнее здесь: https://stackoverflow.com/questions/783 ... r-in-xcode
Мобильная версия