加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift tableView单元格附件类型

发布时间:2020-12-14 05:34:43 所属栏目:百科 来源:网络整理
导读:class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { @IBOutlet var tableView: UITableView var items: String[] = ["We","Heart","Swift"] override func viewDidLoad() { super.viewDidLoad() self.tableView.registerC
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    @IBOutlet
    var tableView: UITableView
    var items: String[] = ["We","Heart","Swift"]

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.registerClass(UITableViewCell.self,forCellReuseIdentifier: "myCell")
    }


    func tableView(tableView: UITableView!,numberOfRowsInSection section: Int) -> Int {
        return self.items.count;
    }

    func tableView(tableView: UITableView!,cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {

        var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("myCell") as UITableViewCell

        cell.textLabel.text = self.items[indexPath.row]
        cell.accessoryType = UITableViewCellAccessoryType.DetailDisclosureButton
        cell.selectionStyle = UITableViewCellSelectionStyle.Blue
        tableView.separatorStyle = UITableViewCellSeparatorStyle.None
        return cell
    }

    func tableView(tableView: UITableView!,didSelectRowAtIndexPath indexPath: NSIndexPath!) {
        println("You selected cell #(indexPath.row)!")

    }
}

我的问题是,附件类型和selectionStyle没有被改变.
tableView.separatorStyle与cell.textlabel.text一样也有改变.
我该如何解决?

UITableViewCellSelectionStyleBlue

The cell has a default background color when selected.

In iOS 7,the selection color is no longer blue. Use
UITableViewCellSelectionStyleDefault instead.

对于附件类型,只要不在其他地方更改它,它应该可以正常工作.确保表宽度正确,否则分隔符可能不在屏幕上.

class ViewController: UIViewController,UITableViewDataSource {

    @IBOutlet
    var tableView: UITableView

    var items: String[] = ["We",cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {

        var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("myCell") as UITableViewCell
        cell.textLabel.text = self.items[indexPath.row]
        cell.selectionStyle = UITableViewCellSelectionStyle.Blue

        /*
        enum UITableViewCellAccessoryType : Int {
        case None // don't show any accessory view
        case DisclosureIndicator // regular chevron. doesn't track
        case DetailDisclosureButton // info button w/ chevron. tracks
        case Checkmark // checkmark. doesn't track
        case DetailButton // info button. tracks
        }
        */

        // Standard options
        cell.accessoryType = UITableViewCellAccessoryType.None
        cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
        cell.accessoryType = UITableViewCellAccessoryType.DetailDisclosureButton
        cell.accessoryType = UITableViewCellAccessoryType.Checkmark
        cell.accessoryType = UITableViewCellAccessoryType.DetailButton

        // Custom view options
        cell.accessoryType = UITableViewCellAccessoryType.None
        cell.accessoryView = UIView(frame: CGRectMake(0,20,20))
        cell.accessoryView.backgroundColor = UIColor.blueColor()

        return cell
    }

    func tableView(tableView: UITableView!,didSelectRowAtIndexPath indexPath: NSIndexPath!) {
        println("You selected cell #(indexPath.row)!")

    }
}

请注意,每次请求单元格时,设置表的separatorStyle并不是一个好的解决方案,而是在加载tableView时执行一次:在viewDidLoad中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读