我是一个完全盲目的开发人员,正在尝试学习Swift和iOS编程。由于在最新的xcode中无法访问界面构建器,因此尝试使用MarkupKit创建UI。我尝试使用一个显示警报的按钮创建一个简单的应用程序。虽然具有正确标题的视图显示按钮没有。根据样本我相信我需要将按钮的值设置为self,但我不确定如何执行此操作。我的view.xml的内容是
<?xml version="1.0" encoding="UTF-8"?>
<!-- Button -->
<?sectionHeaderView?>
<UIButton style="systemButton" normalTitle="Press Me" onTouchUpInside="showGreeting"/>
我的ViewController.swift是
//
// ViewController.swift
// markdownUI
//
// Created by Jared on 3/1/16.
// Copyright © 2016 Jared. All rights reserved.
//
import UIKit
import MarkupKit
class ViewController: UIViewController {
override func loadView() {
view = LMViewBuilder.viewWithName("View", owner: self, root: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
title = "MarkupKit Demo"
}
override func viewWillLayoutSubviews() {
}
func showGreeting() {
let alertController = UIAlertController(title: "Greeting", message: "Hello!", preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler:nil))
presentViewController(alertController, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:0)
即使使用了无关的<?sectionHeaderView?>
PI,您的代码也能正常工作,解析器会忽略它。确保在启动时告诉应用程序哪个视图控制器出现:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow()
window!.rootViewController = UINavigationController(rootViewController: ViewController())
window!.backgroundColor = UIColor.whiteColor()
window!.frame = UIScreen.mainScreen().bounds
window!.makeKeyAndVisible()
return true
}
当应用程序启动时,您应该看到一个导航控制器,其中包含一个按钮,表示&#34;按我&#34;。点击按钮会显示问候语提示。