zoukankan      html  css  js  c++  java
  • swift demo1 tableview

    代码如下:

    //
    //  ViewController.swift
    //  demo1_tableview
    //
    //  Created by Alice_ss on 2018/2/24.
    //  Copyright © 2018年 AC. All rights reserved.
    //
    
    import UIKit
    
    class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
    
        //定义一个tableview
        var tableview :UITableView?
    
        
        override func viewDidLoad() {
            super.viewDidLoad()
            self.tableview = UITableView.init(frame: self.view.frame, style: UITableViewStyle.plain)
            self.tableview?.delegate = self
            self.tableview?.dataSource = self
            self.view .addSubview(self.tableview!)
            
            
        }
        
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            var cell = tableview?.dequeueReusableCell(withIdentifier: "cellID")
            if cell == nil {
                cell = UITableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: "cellID")
            }
            cell?.textLabel?.text = String(indexPath.row)
            return cell!
            
        }
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 10
        }
        func numberOfSections(in tableView: UITableView) -> Int {
            return 1
        }
        func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
            var headerView = UIView.init(frame: CGRect.init(x: 0, y: 0,  UIScreen.main.bounds.size.width, height: <#T##CGFloat#>))
        }
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    
    }

    刚开始看swift项目

    坐下笔记:

    创建一个简单的tablecview项目,就像是上述代码就可以完成了。

    遇到的问题:

    1.添加代理的时候老是报错。后来经过百度,在下边的方法中 定义变量的时候在变量的后边加上? 报错就消失了。但是在使用的时候需要加上一个!才能进行。

    2.其他的跟oc很类似,就不多介绍了。

    对上述的代码,有任何疑问,可以在下方留言。 也可以给我发邮件咨询:673658917@qq.com 或者是直接加qq:673658917 转载请注明出处,谢谢合作。 睡觉舒服,那是给死人准备的,加油吧,一年后你会感谢现在的自己的。
  • 相关阅读:
    execCommand快速实现复制到剪贴板
    webpack安装&指定版本安装&遇到的问题
    promise初体验
    使用原生JS发送AJAX请求(XML,JSON解析)
    【Python3】python中pymysql数据编码的问题
    闭包,闭包用途,call、apply、bind 的用法
    实现一个jQuery API
    Android 客户端和 web服务器通信
    Adb 基础
    在Android 中实现scp操作
  • 原文地址:https://www.cnblogs.com/lishanshan/p/8465793.html
Copyright © 2011-2022 走看看