zoukankan      html  css  js  c++  java
  • Swift

    https://blog.csdn.net/weixin_43704791/article/details/86424080

    2019年01月13日 

    AppDelegate中:

        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

            // Override point for customization after application launch.

            

            let master = MasterViewController()

            let detail = DetailViewController()

            master.detailViewController = detail

            let navigationController = UINavigationController(rootViewController: master)

            //判断设备

            if UIDevice.current.userInterfaceIdiom == .phone{

                self.window?.rootViewController = navigationController

            }else{

                //创建分割视图控制器(iPad特有)

                let split = UISplitViewController()

                //横屏下显示

                split.viewControllers = [navigationController,detail]

                self.window?.rootViewController = split

            }

            return true

        }

    创建MAsterViewController:

    import UIKit

    class MasterViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

        var tableView:UITableView!

        var ctrls = ["A","B","C"]

        var detailViewController:DetailViewController!

        override func viewDidLoad() {

            super.viewDidLoad()

            self.title = "列表"

            self.tableView = UITableView(frame: self.view.frame,style:.plain)

            self.tableView.delegate = self

            self.tableView.dataSource = self

            self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "ReusedCell")

            self.view.addSubview(tableView)

        }

        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

            return ctrls.count

        }

        

        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

            let identifier = "ReusedCell"

            let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)

            cell.accessoryType = .disclosureIndicator

            cell.textLabel?.text = self.ctrls[indexPath.row]

            return cell

        }

        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

            detailViewController!.loadControl(ctrl: self.ctrls[indexPath.row])

    //        detailViewController.title = ctrls[indexPath.row]

            if (UIDevice.current.userInterfaceIdiom == .phone){

             tableView.deselectRow(at: indexPath, animated: true)

                self.navigationController?.pushViewController(detailViewController, animated: true)

            }

        }

        

    }

    DetailViewController:

    import UIKit

    class DetailViewController: UIViewController {

        override func viewDidLoad() {

            super.viewDidLoad()

            self.view.backgroundColor = UIColor.white

            let ctrl = self.title != nil ? self.title! : ""

            loadControl(ctrl: ctrl)

        }

        func loadControl(ctrl:String){

            clearViews()

            switch ctrl {

            case "A":

                let label = UILabel(frame: self.view.bounds)

                label.backgroundColor = UIColor.black

                label.textColor = UIColor.orange

                label.text = "hellow"

                self.view.addSubview(label)

            case "B":

                let button = UIButton(frame: CGRect(x: 150, y: 250, 100, height: 100))

                button.setTitle("按钮", for: .normal)

                button.backgroundColor = UIColor.red

                self.view.addSubview(button)

            case "C":

                let uiSwitch = UISwitch(frame: CGRect(x: 150, y: 250, 0, height: 0))

                uiSwitch.setOn(false, animated: true)

                self.view.addSubview(uiSwitch)

            default:

                print("error")

            }

        }

        func clearViews(){

            for v in self.view.subviews{

                v.removeFromSuperview()

            }

        }

    }

  • 相关阅读:
    farpoint [转]
    用于主题检测的临时日志(07ebc2e2418343fea17b52c9318e7705 3bfe001a32de4114a6b44005b770f6d7)
    将ColumnFooter显示出来,并对相关属性做适当设置。 SetAggregationType接口可以帮助你方便的完成求和需求。
    单元测试
    c#扩展方法
    String.Format格式说明
    vs 2005断点调试[转]
    EventLog 类【转】
    From Single PDF template Make a series PDF
    PDF template and print
  • 原文地址:https://www.cnblogs.com/sundaysme/p/10341456.html
Copyright © 2011-2022 走看看