swiftt之表格控件(UITableView)详解,出错,求指南

swiftt之表格控件(UITableView)详解,出错,求指南,第1张

概述1、问题描述       最后的界面上什么都没有,空白的。如下图: 2、敢问:问题出在什么地方? 3、代码如下: import UIKitenum UIControlType{ case Basic; case Advanced;}class ViewController: UIViewController, UITableViewDataSource, UITable

1、问题描述

最后的界面上什么都没有,空白的。如下图:


2、敢问:问题出在什么地方?

3、代码如下:

import UIKitenum UIControlType{    case Basic;    case Advanced;}class VIEwController: UIVIEwController,UItableVIEwDataSource,UItableVIEwDelegate{            var tableVIEw:UItableVIEw?;    var ctrnames:[String] = ["按钮UIbutton","标签UILabel","文本框UITextFIEld"];    var allnames:Dictionary<Int,[String]>?;    var adheader:[String]?;    var controlType:UIControlType?;        overrIDe func loadVIEw()    {        super.loadVIEw();    }        overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()                /// 初始化数据,把这次数据放在属性列表文件里        allnames = [0:ctrnames,1:[String]([            "UIDatePicker 日期选择器","UIWebVIEw 网页选择器","UIToolbar 工具条"])];                        self.adheader = ["常见 UIkit 控件","高级UIKIt控件"];    }            @IBAction func plainClicked(sender:UIbarbuttonItem)    {        controlType = UIControlType.Basic;                /// 创建表视图        self.tableVIEw = UItableVIEw(frame: CGRectMake(0,100,vIEw.frame.size            .wIDth,vIEw.frame.size.height - 100),style: UItableVIEwStyle.Plain);        self.tableVIEw!.delegate = self;        self.tableVIEw!.dataSource = self;                /// 创建单元格        self.tableVIEw!.registerClass(UItableVIEwCell.self,forCellReuseIDentifIEr: "SwiftCell");        self.vIEw.addSubvIEw(self.tableVIEw!);                /// 创建标签头        let headerLabel = UILabel(frame: CGRectMake(0,vIEw.bounds.size            .wIDth,30));        headerLabel.backgroundcolor = UIcolor.blackcolor();        headerLabel.textcolor = UIcolor.whitecolor();        headerLabel.numberOflines = 0;        headerLabel.lineBreakMode = NSlineBreakMode.ByCharWrapPing;        headerLabel.text = "常见UIKit控件";        headerLabel.Font = UIFont.italicSystemFontOfSize(20);                /// 将label显示到tableVIEw中        self.tableVIEw!.tableheaderVIEw = headerLabel;    }        @IBAction func groupClickd(sender:UIbarbuttonItem)    {        controlType = UIControlType.Advanced;                /// 创建视图        self.tableVIEw = UItableVIEw(frame: CGRectMake(0,vIEw.frame.size.wIDth,vIEw.frame.size            .height - 100),style: UItableVIEwStyle.Grouped);                self.tableVIEw!.delegate = self;        self.tableVIEw!.dataSource = self;                        /// 创建单元格        self.tableVIEw!.registerClass(UItableVIEwCell.self,forCellReuseIDentifIEr: "SwiftCell");                self.vIEw.addSubvIEw(self.tableVIEw!);                        /// 创建标签头        let headerLabel = UILabel(frame: CGRectMake(0,30));        headerLabel.backgroundcolor = UIcolor.blackcolor();        headerLabel.textcolor = UIcolor.whitecolor();        headerLabel.numberOflines = 0;        headerLabel.lineBreakMode = NSlineBreakMode.ByCharWrapPing;        headerLabel.text = "高级UIKit控件";        headerLabel.Font = UIFont.italicSystemFontOfSize(20);                self.tableVIEw!.tableheaderVIEw = headerLabel;    }        /// 创建分区    func numberOfSectionsIntableVIEw(table:UItableVIEw)->Int    {        return controlType == UIControlType.Basic ? 1:2;    }    /// 返回行数    func tableVIEw(tableVIEw:UItableVIEw,numberOfRowsInSection section:Int)->Int    {        let data = allnames![section];        return data!.count;    }    /// 协议中得方法,该方法的返回值决定指定分区的头部    func tableVIEw(table:UItableVIEw,TitleForheaderInSection section:Int)->String?    {        return adheader?[section];    }    /// 协议中的方法,该方法的返回值决定指定分区的尾部    func tableVIEw(table:UItableVIEw,TitleForFooterInSection section:Int)->String?    {        return "有\(allnames![section]!.count)个控件";    }        func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell {                let IDentify = "SwiftCell";                let cell = tableVIEw.dequeueReusableCellWithIDentifIEr(IDentify,forIndexPath: indexPath);        cell.accessoryType = UItableVIEwCellAccessoryType.disclosureIndicator;        let secno = indexPath.section;        let data = allnames![secno];        cell.textLabel?.text = data![indexPath.row];                return cell;    }        /// UItableVIEwDelegate 方法,处理列表项的选中事件    func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath)    {                tableVIEw.deselectRowAtIndexPath(indexPath,animated: true);        let itemString = ctrnames[indexPath.row];                /// 创建提示框        let alertVIEw = UIAlertController(Title: "提示",message: "你选中了\(itemString)",preferredStyle: .Alert);        /// 向提示框中增加按钮        let alertAction = UIAlertAction(Title: "确定",style: UIAlertActionStyle.Default,handler: {(action)->VoID in});        alertVIEw.addAction(alertAction);                presentVIEwController(alertVIEw,animated:true,completion:nil);    }            overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}
4、UItableVIEw控件详解

总结

以上是内存溢出为你收集整理的swiftt之表格控件(UITableView)详解,出错,求指南全部内容,希望文章能够帮你解决swiftt之表格控件(UITableView)详解,出错,求指南所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1079128.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存