1 //2 //Jietableviewcontroller.swift3 //Jietableview4 //5 //Created by Jiezhang on 14-10-5.6 //Copyright (c) 2014 Jiezhang. All rights reserved.7 //8 9 ImportUIKitTen One classJietableviewcontroller:uitableviewcontroller { A -var listvideos:nsmutablearray! - the override func Viewdidload () { - Super. Viewdidload () -var bundle =Nsbundle.mainbundle () -Let plistpath:string! = Bundle.pathforresource ("Videos", OfType: "Plist") +Listvideos =Nsmutablearray (Contentsoffile:plistpath) - //uncomment the following line to preserve selection between presentations + //Self.clearsselectiononviewwillappear = False A at //uncomment the following line to display a Edit button in the navigation bar for this view controller. - //The following paragraph is set to edit on the left, add item to the right - -Self.navigationItem.leftBarButtonItem =Self.editbuttonitem () -Let AddButton = Uibarbuttonitem (BARBUTTONSYSTEMITEM:UIBARBUTTONSYSTEMITEM.ADD, target:self, action: "Insertnewobject :") -Self.navigationItem.rightBarButtonItem =AddButton in - } to + func Insertnewobject (sender:anyobject) { -var item:nsdictionary = nsdictionary (objects:["http://c.hiphotos.baidu.com/video/pic/item/ F703738da977391224eade15fb198618377ae2f2.jpg "," New Data ", Nsdate.date (). Description], Forkeys: [" video_img "," Video_ Title "," Video_subtitle "]) theListvideos.insertobject (item, atindex:0) *Let Indexpath = Nsindexpath (forrow:0, insection:0) $ self.tableView.insertRowsAtIndexPaths ([Indexpath], withrowanimation:. Automatic)Panax Notoginseng } - the + override func didreceivememorywarning () { A Super. didreceivememorywarning () the //Dispose of any resources the can be recreated. + } - $ //MARK:-Table View Data source $ //returns the number of sections -Override func Numberofsectionsintableview (Tableview:uitableview)Int { - //#warning potentially incomplete method implementation. the //Return the number of sections. - return1Wuyi } the //returns the number of rows in a section -Override Func TableView (Tableview:uitableview, numberofrowsinsection section:int)Int { Wu //#warning Incomplete method implementation. - //Return The number of the rows in the section. About returnListvideos.count $ } - //provides data for a table view cell, which is a method that must be implemented -Override Func TableView (Tableview:uitableview, Cellforrowatindexpath Indexpath:nsindexpath)UITableViewCell { -Let cellidentifier:string = "Videoitem" ALet cell =Tableview.dequeuereusablecellwithidentifier (Cellidentifier, Forindexpath:indexpath) as JieTableViewCell +var row =Indexpath.row thevar rowdict:nsdictionary =Listvideos.objectatindex (Row) as Nsdictionary -Let url:string = Rowdict.objectforkey ("video_img") as String $Let Dataimg:nsdata =NSData (Contentsofurl:nsurl (string:url)) theCell. Jievideoimg.image =UIImage (data:dataimg) theCell. Jievideotitle.text = Rowdict.objectforkey ("Video_title") as?String theCell. Jievideosubtitle.text = Rowdict.objectforkey ("Video_subtitle") as?String the returnCell - in } the the override func TableView (Tableview:uitableview, Didselectrowatindexpath indexpath:nsindexpath) { About the } the the //support for cell editing functions +Override Func TableView (Tableview:uitableview, Caneditrowatindexpath Indexpath:nsindexpath)Bool { - //Return NO If you don't want the specified item to be editable. the return trueBayi } the the //Override to support editing the table view. - override func TableView (Tableview:uitableview, Commiteditingstyle Editingstyle:uitableviewcelleditingstyle, for Rowatindexpath Indexpath:nsindexpath) { - ifEditingstyle = = . Delete { the //Delete The row from the data source the Listvideos.removeobjectatindex (Indexpath.row) the tableview.deleterowsatindexpaths ([Indexpath], withrowanimation:. Fade) the}Else ifEditingstyle = = . Insert { - //Create A new instance of the appropriate class, insert it into the array, and add a new row to the table view the } the } the 94 the //Override to support rearranging the table view. the override func TableView (Tableview:uitableview, Moverowatindexpath Fromindexpath:nsindexpath, Toindexpath:nsinde XPath) { the ifFromindexpath! =toindexpath{98var object:anyobject =Listvideos.objectatindex (Fromindexpath.row) About Listvideos.removeobjectatindex (Fromindexpath.row) - ifToindexpath.row >self.listvideos.count{101 Self.listVideos.addObject (object)102}Else{103 Self.listVideos.insertObject (object, AtIndex:toIndexPath.row)104 } the }106 }107 108 109 the //Override to support conditional rearranging of the table view.111 //in edit state, you can drag to set the item location theOverride Func TableView (Tableview:uitableview, Canmoverowatindexpath Indexpath:nsindexpath)Bool {113 //Return NO If you don't want the item to be re-orderable. the return true the } the 117 118 119 //MARK:-Navigation - 121 //pass values to the newly entered interface122Override Func Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject!) {123 ifSegue.identifier = = "ShowDetail" {124 ifLet Indexpath =Self.tableView.indexPathForSelectedRow () { theLet object:nsdictionary =Listvideos[indexpath.row] as Nsdictionary126(Segue.destinationviewcontroller as Jiedetailviewcontroller). Detailitem =Object127 } - }129 } the 131 the 133 134}
Swift Tableviewcontroller Custom List