1. 程式人生 > >swift學習(1)----tableVIew

swift學習(1)----tableVIew

import UIKit

class MyTableViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{

   
var myTableView:UITableView!
   
var items1 = ["one","two","three"]
   
var items2 = ["1","2","3"]
   
var addButton:UIButton!
   
var delButton:UIButton!
   
   
overridefunc viewDidLoad() {
       
super.viewDidLoad()
       
myTableView = UITableView()
       
myTableView.delegate = self;
       
myTableView.dataSource = self;
       
       
myTableView.frame = CGRect(x: 10, y: 30, width: self.view.frame.width-20, height: 500);
       
myTableView.delegate = self self.view.addSubview
(myTableView)
       
       
addButton = UIButton(type: UIButtonType.System)
       
addButton.frame = CGRect(x: 10, y: 30, width: 100, height: 44)
       
addButton.setTitle("新增", forState: UIControlState.Normal)
       
addButton.addTarget(self, action: "add:", forControlEvents: UIControlEvents
.TouchUpInside)
       
       
self.view.addSubview(addButton)
       
       
delButton = UIButton(type: UIButtonType.System)
       
delButton.frame = CGRect(x: 150, y: 30, width: 100, height: 44)
       
delButton.setTitle("刪除", forState: UIControlState.Normal)
       
delButton.addTarget(self, action: "del:", forControlEvents: UIControlEvents.TouchUpInside)
       
self.view.addSubview(delButton)
       
       
// Do any additional setup after loading the view.
    }
   
//新增 func add(sender:UIButton){
       
items1.append("New....")
       
myTableView.reloadData()

       
print("add")
    }
   
//刪除 func del(sender:UIButton){
       
items1.removeAtIndex(0)
       
myTableView.reloadData()
       
       
print("del")
       
    }

   
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       
returnitems1.count;
    }
   
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
       
return1
    }
   
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
       
let cid = "cid" var cell:UITableViewCell!
        cell = tableView.
dequeueReusableCellWithIdentifier(cid)
       
if cell == nil{
            cell =
UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: cid)
           
        }
        cell.
imageView?.image = UIImage(named:"2.jpg")
        cell.
textLabel?.text = items1[indexPath.row]
        cell.
detailTextLabel?.text = "速回復i雙基色"
        cell.
accessoryType = UITableViewCellAccessoryType.DetailButton return cell

    }
   
overridefunc didReceiveMemoryWarning() {
       
super.didReceiveMemoryWarning()
       
// Dispose of any resources that can be recreated.
    }
   

相關推薦

swift學習1----tableVIew

import UIKitclass MyTableViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{     var myTableView:UITableView!     var items1 = [

redis學習1--- NoSQL介紹

redis學習 模型 width 快速查詢 init 文件 borde 處理 only 一、NoSQL介紹 1、什麽是NoSQL NoSQL = Not Only SQL 非關系型數據庫 2、為什麽用NoSQL High performance - 高

ArcGIS API for JavaScript學習1:第一個地圖

樣式表 參數 資源 charset 底層 arcgis 順序 api navi 1.簡介 ArcGIS API for JavaScript跟隨ArcGIS 9.3同時發布,是ESRI根據JavaScript技術實現的調用ArcGIS Server REST API接口的一

Linux學習1

linux開始學習Linux了,希望能學有所成————測試中本文出自 “Linux學習” 博客,請務必保留此出處http://mmchy.blog.51cto.com/13044974/1941714Linux學習(1)

facets學習1:什麽是facets

遺失 air 不同的 無縫切換 over 快速 後來 樣式 觀察 ML 數據集可以包含數億個數據點,每個數據點由數百(甚至數千)的特征組成,幾乎不可能以直觀的方式了解整個數據集。為幫助理解、分析和調試 ML 數據集,谷歌開源了 Facets,一款可視化工具。 Facets

C++學習1:最大子段和多種解法

多少 問題: code namespace 數據 組成 amp using () 問題:給定由n個數(可能為負數)組成的序列a1,a2,a3,...,an,求該序列子段和的最大值。 第一種解法:(最容易考慮的方法,將所有的子段一一相加,然後比較) 1 #include&

嵌入式開發學習1<ARM體系結構>

特點 如何 現在 訪問 任務 物聯網 嵌入 專用 arm1 SoC : 在cpu 裏內嵌了很多外設,現在所說的cpu 實際上都是SoC。 32位cpu指的是數據總線是32位的。 32位的地址總線尋址範圍是4G。2的32次方。 CISC complex instruction

IDEA 學習筆記之 Java項目開發深入學習1

java項目 bsp 重構 str 代碼提示 log pan ora tro Java項目開發深入學習(1): 定義編譯輸出路徑: 繼承以上工程配置 重新定義新的項目編譯路徑 添加source目錄:點擊添加,再點擊移除: 編譯項目: 常用快捷鍵總結: Ctr

nodejs學習1

管理工具 cti 分享 環境 scrip alt world 命令提示符 true 1.安裝:可以在http://nodejs.org/dist/下載nodejs的所有版本,我在裏面下載了node-v8.9.0-x64.msi,安裝完成,在命令提示符中輸入“node --v

Win10下Docker學習1安裝

ner table 組成 高效率 down 提高 打開 cpu 其他人 Docker簡介 Docker 是一個開源的應用容器引擎,讓開發者可以打包他們的應用以及依賴包到一個可移植的容器中,然後發布到任何流行的 Linux 機器上,也可以實現虛擬化。容器是完全使用沙箱機制,

Vue深度學習1

msg 第一個 數據綁定 vue.js 這就是 one round 本質 dex Hello World 現在就讓我們來寫第一個vue.js的實例。如下代碼: html代碼: <div id="demo"> {{ message }}

腳本學習1列出一組IP內所有活動主機

cat -c spa ash 活動 pin null status amp 1、用ping命令編寫腳本來查詢一組IP地址同時檢查他們是否處於活動狀態 1 [zhi@centos7 ~]$ vi CheckHostStatus.sh 2 [zhi@centos7 ~]$

Python爬蟲學習1

數據 bin des fin load 寫入 all pytho urlopen 接觸python不久,也在慕課網學習了一些python相關基礎,對於爬蟲初步認為是依靠一系列正則獲取目標內容數據 於是參照著慕課網上的教學視頻,完成了我的第一個python爬蟲,雞凍 >

Docker學習1安裝

www. ati https 機制 生產環境 開機啟動 works tab 流行 1. Docker簡介 Docker 是一個開源的應用容器引擎,讓開發者可以打包他們的應用以及依賴包到一個可移植的容器中,然後發布到任何流行的 Linux 機器上,也可以實現虛擬化。容器是完全

Hibernate學習1簡單介紹

清理緩存 並發 connect upgrade 定義 之前 對象 value cat 1.什麽是Hibernate? ????????? 首先,Hibernat

shell腳本學習1

數字 空格 shell chm bubuko 括號 bin clas 存在 格式: #!/bin/bash :標誌一個shell腳本 #Filename:first_shell.sh :文件名稱 #

perl學習1基本語法

log 跳過 默認值 斜線 進位 字母 劃線 小寫 perl 一: 如何運行   在linux終端,直接輸入 perl filenaem.pl   Perl腳本在解釋執行時和shell腳本一樣,自頂向下,跳過sub定義部分依次執行。 二:標量 1:  標量     可以是數

spark學習1--ubuntu14.04集群搭建、配置jdk

RM int 5.0 java_home 輸入 str cas Go 比較 環境:ubuntu14.04 1、文本模式桌面模式切換 ctrl+alt+F6 切換到文本模式 ctrl + alt +F7 /輸入命令startx切換到桌面模式 2、更改Ip地址、主機名 /

機器學習1 - TensorflowSharp 簡單使用與KNN識別MNIST流程

定義 機器學習算法 三角形 演示 ron static 分享 con 區別 機器學習是時下非常流行的話題,而Tensorflow是機器學習中最有名的工具包。TensorflowSharp是Tensorflow的C#語言表述。本文會對TensorflowSharp的使用進行一

Hibernate學習1- 初識

his HA logs ply func 對數 事務管理 arch 優化 一、概念引入 1、持久化:   狹義概念:數據存儲在物理介質不會丟失。   廣義概念:對數據的CRUD操作都叫做持久化。 2、加載: hibernate裏,數據從數據庫中加載到session。