Swift

? ? ? ? let vc = ViewController.init()

? ? ? ? letnav =UINavigationController.init(rootViewController: vc)

? ? ? ? self.window?.rootViewController = nav


ViewController.swift

import UIKit

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate{

? ? // 存放數(shù)據(jù)的字典

? ? varcells :NSDictionary?

? ? // 表格

? ? vartableView:UITableView?

? ? // UITableViewDataSource

? ? functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

? ? ? ? return(cells?.allKeys.count)!

? ? }


? ? functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{

? ? ? ? letstr ="cell"

? ? ? ? varcell = tableView.dequeueReusableCell(withIdentifier: str)

? ? ? ? ifcell ==nil{

? ? ? ? ? ? cell =UITableViewCell.init(style: .default, reuseIdentifier: str)

? ? ? ? }

? ? ? ? cell?.textLabel?.text=cells?.allKeys[indexPath.row]as?String;

? ? ? ? returncell!

? ? }


? ? // 點(diǎn)擊按鈕跳轉(zhuǎn)

? ? functableView(_tableView:UITableView, didSelectRowAt indexPath:IndexPath) {

? ? ? ? ifindexPath.row==0{

? ? ? ? ? ? letsec =SecendViewController.init()

? ? ? ? ? ? // 將值傳到下一個(gè)界面

? ? ? ? ? ? sec.data=cells?["國(guó)內(nèi)"]as?NSDictionary

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

? ? ? ? }else{

? ? ? ? ? ? letsec =SecendViewController.init()

? ? ? ? ? ? // 將值傳到下一個(gè)界面

? ? ? ? ? ? sec.data=cells?["國(guó)外"]as?NSDictionary

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

? ? ? ? }

? ? }

? ? overridefuncviewDidLoad() {

? ? ? ? super.viewDidLoad()

? ? ? ? // 初始化表格

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

? ? ? ? // 表格的協(xié)議跟代理

? ? ? ? tableView?.delegate=self

? ? ? ? tableView?.dataSource=self

? ? ? ? // 添加到視圖上

? ? ? ? self.view.addSubview(tableView!)


? ? ? ? // 獲得plist文件到地址

? ? ? ? letpath =Bundle.main.bundlePath

? ? ? ? letplistName:NSString="Property List.plist"

? ? ? ? letfinalPath:NSString= (pathasNSString).appendingPathComponent(plistNameasString)asNSString

? ? ? ? cells=NSDictionary(contentsOfFile:finalPathasString)

? ? }

SecendViewController.swift

import UIKit

class SecendViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

? ? // 存放數(shù)據(jù)的字典

? ? vardata :NSDictionary?

? ? // 表格

? ? vartableView:UITableView?

? ? // UITableViewDataSource

? ? functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

? ? ? ? return(data?.allKeys.count)!

? ? }


? ? functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{

? ? ? ? letstr ="cell"

? ? ? ? varcell = tableView.dequeueReusableCell(withIdentifier: str)

? ? ? ? ifcell ==nil{

? ? ? ? ? ? cell =UITableViewCell.init(style: .default, reuseIdentifier: str)

? ? ? ? }

? ? ? ? cell?.textLabel?.text=data?.allKeys[indexPath.row]as?String;

? ? ? ? returncell!

? ? }

? ? functableView(_tableView:UITableView, didSelectRowAt indexPath:IndexPath) {

? ? ? ? ifindexPath.row==0{

? ? ? ? ? ? letsec =ThirdViewController.init()

? ? ? ? ? ? sec.data=data?["國(guó)內(nèi)"]as?NSDictionary

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

? ? ? ? }else{

? ? ? ? ? ? letsec =ThirdViewController.init()

? ? ? ? ? ? sec.data=data?["國(guó)外"]as?NSDictionary

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

? ? ? ? }

? ? }

? ? overridefuncviewDidLoad() {

? ? ? ? super.viewDidLoad()

? ? ? ? // 初始化表格

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

? ? ? ? // 表格的協(xié)議跟代理

? ? ? ? tableView?.delegate=self

? ? ? ? tableView?.dataSource=self

? ? ? ? // 添加到視圖上

? ? ? ? self.view.addSubview(tableView!)

? ? ? ? // Do any additional setup after loading the view.

? ? }

ThirdViewController.swift

import UIKit

class ThirdViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

? ? // 存放數(shù)據(jù)的字典

? ? vardata :NSDictionary?

? ? // 表格

? ? vartableView:UITableView?

? ? // UITableViewDataSource

? ? functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

? ? ? ? return3

? ? }


? ? functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{

? ? ? ? letstr ="cell"

? ? ? ? varcell = tableView.dequeueReusableCell(withIdentifier: str)

? ? ? ? ifcell ==nil{

? ? ? ? ? ? cell =UITableViewCell.init(style: .default, reuseIdentifier: str)

? ? ? ? }

? ? ? ? letdata = ["謝霆鋒","周杰倫","劉德華"];

? ? ? ? cell?.textLabel?.text= data[indexPath.row];

? ? ? ? returncell!

? ? }


? ? functableView(_tableView:UITableView, didSelectRowAt indexPath:IndexPath) {

? ? ? ? ? ? letsec =FoutViewController.init()

//? ? ? ? ? ? sec.data = data?["國(guó)外"] as? NSDictionary

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


? ? }

? ? overridefuncviewDidLoad() {

? ? ? ? super.viewDidLoad()

? ? ? ? // 初始化表格

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

? ? ? ? // 表格的協(xié)議跟代理

? ? ? ? tableView?.delegate=self

? ? ? ? tableView?.dataSource=self

? ? ? ? // 添加到視圖上

? ? ? ? self.view.addSubview(tableView!)


? ? ? ? // Do any additional setup after loading the view.

? ? }

FourViewController.swift

import UIKit

class FoutViewController: UIViewController ,UITableViewDataSource,UITableViewDelegate {

? ? // 存放數(shù)據(jù)的字典

? ? vardata :NSDictionary?

? ? // 表格

? ? vartableView:UITableView?

? ? // UITableViewDataSource

? ? functableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

? ? ? ? return2

? ? }


? ? functableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{

? ? ? ? letstr ="cell"

? ? ? ? varcell = tableView.dequeueReusableCell(withIdentifier: str)

? ? ? ? ifcell ==nil{

? ? ? ? ? ? cell =UITableViewCell.init(style: .default, reuseIdentifier: str)

? ? ? ? }

? ? ? ? letdata = ["因?yàn)閻鬯詯?,"只要為你活一天"];

? ? ? ? cell?.textLabel?.text= data[indexPath.row];

? ? ? ? returncell!

? ? }


? ? functableView(_tableView:UITableView, didSelectRowAt indexPath:IndexPath) {

? ? ? ? let sec = MusicViewController.init()

? ? ? ? //? ? ? ? ? ? sec.data = data?["國(guó)外"] as? NSDictionary

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

? ? }

? ? overridefuncviewDidLoad() {

? ? ? ? super.viewDidLoad()

? ? ? ? // 初始化表格

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

? ? ? ? // 表格的協(xié)議跟代理

? ? ? ? tableView?.delegate=self

? ? ? ? tableView?.dataSource=self

? ? ? ? // 添加到視圖上

? ? ? ? self.view.addSubview(tableView!)


? ? ? ? // Do any additional setup after loading the view.

? ? }


MusicViewController.Swift

import UIKit

importAVFoundation

classMusicViewController:UIViewController{

varaudioPlayer:AVAudioPlayer?

? ? overridefuncviewDidLoad() {

? ? ? ? super.viewDidLoad()

? ? ? ? self.view.backgroundColor = .white

? ? ? ? // 設(shè)置音樂(lè)名稱的標(biāo)簽

? ? ? ? letlab =UILabel.init(frame:CGRect(x:0, y:100, width:self.view.frame.size.width, height:30))

? ? ? ? lab.text="因?yàn)閻鬯詯?

? ? ? ? lab.backgroundColor = .red

? ? ? ? lab.textColor= .black;

? ? ? ? lab.textAlignment= .center

? ? ? ? self.view.addSubview(lab)

? ? ? ? // 設(shè)置音樂(lè)

? ? ? ? let path = Bundle.main.path(forResource: "%E5%BC%A0%E7%B4%AB%E8%B1%AA+-+%E5%8F%AF%E4%B8%8D%E5%8F%AF%E4%BB%A5", ofType: "flac")

? ? ? ? letpathURL=NSURL(fileURLWithPath: path!)

? ? ? ? do{

? ? ? ? ? ? audioPlayer=tryAVAudioPlayer(contentsOf: pathURLasURL)

? ? ? ? }catch{

? ? ? ? ? ? audioPlayer=nil

? ? ? ? }


? ? ? ? audioPlayer?.prepareToPlay()

? ? ? ? // 播放按鈕

? ? ? ? letplaybtn =UIButton(frame:CGRect(x:60, y:200, width:100, height:40))

? ? ? ? playbtn.backgroundColor=UIColor.cyan

? ? ? ? playbtn.setTitle("play", for: .normal)

? ? ? ? playbtn.setTitleColor(UIColor.white, for: .normal)


? ? ? ? // 暫停按鈕

? ? ? ? letpausebtn =UIButton(frame:CGRect(x:180, y:200, width:100, height:40))

? ? ? ? pausebtn.setTitle("pause", for: .normal)

? ? ? ? pausebtn.setTitleColor(UIColor.white, for: .normal)

? ? ? ? pausebtn.backgroundColor=UIColor.cyan


? ? ? ? // 添加到視圖上

? ? ? ? self.view.addSubview(playbtn)

? ? ? ? self.view.addSubview(pausebtn)


? ? ? ? // 按鈕方法

? ? ? ? playbtn.addTarget(self, action:#selector(play), for: .touchUpInside)

? ? ? ? pausebtn.addTarget(self, action:#selector(pause), for: .touchUpInside)




? ? ? ? self.view.addSubview(playbtn)

? ? ? ? self.view.addSubview(pausebtn)


? ? ? ? // Do any additional setup after loading the view.

? ? }

? ? @objcfuncplay(){

? ? ? ? audioPlayer?.play()

? ? }

? ? @objcfuncpause(){

? ? ? ? audioPlayer?.pause()

? ? }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末玛臂,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子封孙,更是在濱河造成了極大的恐慌迹冤,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,907評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件虎忌,死亡現(xiàn)場(chǎng)離奇詭異泡徙,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)膜蠢,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,987評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門堪藐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人狡蝶,你說(shuō)我怎么就攤上這事庶橱≈” “怎么了贪惹?”我有些...
    開封第一講書人閱讀 164,298評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)寂嘉。 經(jīng)常有香客問(wèn)我奏瞬,道長(zhǎng),這世上最難降的妖魔是什么泉孩? 我笑而不...
    開封第一講書人閱讀 58,586評(píng)論 1 293
  • 正文 為了忘掉前任硼端,我火速辦了婚禮,結(jié)果婚禮上寓搬,老公的妹妹穿的比我還像新娘珍昨。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,633評(píng)論 6 392
  • 文/花漫 我一把揭開白布镣典。 她就那樣靜靜地躺著兔毙,像睡著了一般。 火紅的嫁衣襯著肌膚如雪兄春。 梳的紋絲不亂的頭發(fā)上澎剥,一...
    開封第一講書人閱讀 51,488評(píng)論 1 302
  • 那天,我揣著相機(jī)與錄音赶舆,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛惫皱,可吹牛的內(nèi)容都是我干的产镐。 我是一名探鬼主播,決...
    沈念sama閱讀 40,275評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼九串,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼宛乃!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起蒸辆,我...
    開封第一講書人閱讀 39,176評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤征炼,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后躬贡,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體谆奥,經(jīng)...
    沈念sama閱讀 45,619評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,819評(píng)論 3 336
  • 正文 我和宋清朗相戀三年拂玻,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了酸些。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,932評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡檐蚜,死狀恐怖魄懂,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情闯第,我是刑警寧澤市栗,帶...
    沈念sama閱讀 35,655評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站咳短,受9級(jí)特大地震影響填帽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜咙好,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,265評(píng)論 3 329
  • 文/蒙蒙 一篡腌、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧勾效,春花似錦嘹悼、人聲如沸叛甫。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,871評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)合溺。三九已至,卻和暖如春缀台,著一層夾襖步出監(jiān)牢的瞬間棠赛,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,994評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工膛腐, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留睛约,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,095評(píng)論 3 370
  • 正文 我出身青樓哲身,卻偏偏與公主長(zhǎng)得像辩涝,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子勘天,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,884評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴(yán)謹(jǐn) 對(duì)...
    cosWriter閱讀 11,101評(píng)論 1 32
  • 1.ios高性能編程 (1).內(nèi)層 最小的內(nèi)層平均值和峰值(2).耗電量 高效的算法和數(shù)據(jù)結(jié)構(gòu)(3).初始化時(shí)...
    歐辰_OSR閱讀 29,385評(píng)論 8 265
  • 概述在iOS開發(fā)中UITableView可以說(shuō)是使用最廣泛的控件怔揩,我們平時(shí)使用的軟件中到處都可以看到它的影子,類似...
    liudhkk閱讀 9,043評(píng)論 3 38
  • 第一章 來(lái)到重慶的偶遇 一下飛機(jī)就聽到幾個(gè)女生不顧形象的亂叫脯丝。商膊。。 沒錯(cuò)宠进,就是我們幾個(gè)姐妹晕拆,呃。材蹬。实幕。不好意思忘記...
    源來(lái)凱始璽歡妳L閱讀 188評(píng)論 0 1
  • 旅游后遺癥,昨天中午吹空調(diào)堤器,竟然感冒了昆庇,這么熱的天可是真不好受,提醒小伙伴們要注意休息啊闸溃。 現(xiàn)在越來(lái)越發(fā)現(xiàn)口才是人...
    鮮嫩多汁小肉包閱讀 150評(píng)論 0 3