? ? ? ? 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()
? ? }