首先建立一个swift项目,把storyboard的内容删掉,添加一个 Navigation Controller,然后设置storyboard对应界面的class,在Navigation Controller界面设置View Controller的is initial View Controller,这里使用的自定义列表内容,所以要新建一个继承UITableViewCell的类,然后设置storyboard中Table View的Prototype Cells的class,对于点击item进入详情界面,使用TableView 中的prepareForSegue方法。
JieTableViewController.swift
-   
 
- import UIKit  
 
-   
 
- class JieTableViewController: UITableViewController {  
 
-   
 
-     var listVideos : NSMutableArray!  
 
-       
 
-     override func viewDidLoad() {  
 
-         super.viewDidLoad()  
 
-         var bundle = NSBundle.mainBundle()  
 
-         let plistPath : String! = bundle.pathForResource("videos", ofType: "plist")  
 
-         listVideos = NSMutableArray(contentsOfFile: plistPath)  
 
-         
 
-         
 
-           
 
-         
 
-         
 
-           
 
-         self.navigationItem.leftBarButtonItem = self.editButtonItem()  
 
-         let addButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "insertNewObject:")  
 
-         self.navigationItem.rightBarButtonItem = addButton  
 
-           
 
-     }  
 
-   
 
-     func insertNewObject(sender: AnyObject) {  
 
-         var item : NSDictionary = NSDictionary(objects:["http://c.hiphotos.baidu.com/video/pic/item/f703738da977391224eade15fb198618377ae2f2.jpg","新增数据", NSDate.date().description] , forKeys: ["video_img","video_title","video_subTitle"])  
 
-         listVideos.insertObject(item, atIndex: 0)  
 
-         let indexPath = NSIndexPath(forRow: 0, inSection: 0)  
 
-         self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)  
 
-     }  
 
-       
 
-   
 
-     override func didReceiveMemoryWarning() {  
 
-         super.didReceiveMemoryWarning()  
 
-         
 
-     }  
 
-   
 
-     
 
-     
 
-     override func numberOfSectionsInTableView(tableView: UITableView) -> Int {  
 
-         
 
-         
 
-         return 1  
 
-     }  
 
-     
 
-     override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {  
 
-         
 
-         
 
-         return listVideos.count  
 
-     }  
 
-     
 
-     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {  
 
-         let cellIdentifier : String = "videoItem"  
 
-         let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as JieTableViewCell  
 
-         var row = indexPath.row  
 
-         var rowDict : NSDictionary = listVideos.objectAtIndex(row) as NSDictionary  
 
-         let url : String = rowDict.objectForKey("video_img") as String  
 
-         let dataImg : NSData = NSData(contentsOfURL: NSURL(string : url))  
 
-         cell.JieVideoImg.image = UIImage(data: dataImg)  
 
-         cell.JieVideoTitle.text = rowDict.objectForKey("video_title") as? String  
 
-         cell.JieVideoSubTitle.text = rowDict.objectForKey("video_subTitle") as? String  
 
-         return cell  
 
-   
 
-     }  
 
-       
 
-     override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {  
 
-   
 
-     }  
 
-       
 
-     
 
-     override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {  
 
-         
 
-         return true  
 
-     }  
 
-       
 
-     
 
-     override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {  
 
-         if editingStyle == .Delete {  
 
-             
 
-             listVideos.removeObjectAtIndex(indexPath.row)  
 
-             tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)  
 
-         } else if editingStyle == .Insert {  
 
-             
 
-         }      
 
-     }  
 
-   
 
-       
 
-     
 
-     override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {  
 
-         if fromIndexPath != toIndexPath{  
 
-             var object: AnyObject = listVideos.objectAtIndex(fromIndexPath.row)  
 
-             listVideos.removeObjectAtIndex(fromIndexPath.row)  
 
-             if toIndexPath.row > self.listVideos.count{  
 
-                 self.listVideos.addObject(object)  
 
-             }else{  
 
-                 self.listVideos.insertObject(object, atIndex: toIndexPath.row)  
 
-             }  
 
-         }  
 
-     }  
 
-       
 
-   
 
-       
 
-     
 
-     
 
-     override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {  
 
-         
 
-         return true  
 
-     }  
 
-       
 
-   
 
-       
 
-     
 
-   
 
-     
 
-     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {  
 
-         if segue.identifier == "showDetail" {  
 
-             if let indexPath = self.tableView.indexPathForSelectedRow() {  
 
-                 let object : NSDictionary = listVideos[indexPath.row] as NSDictionary  
 
-                 (segue.destinationViewController as JieDetailViewController).detailItem = object  
 
-             }  
 
-         }  
 
-     }  
 
-   
 
-       
 
-       
 
-   
 
- }  
 
 
JieTableViewCell.swift
-   
 
- import UIKit  
 
-   
 
- class JieTableViewCell: UITableViewCell {  
 
-   
 
-     @IBOutlet weak var JieVideoImg: UIImageView!  
 
-     @IBOutlet weak var JieVideoTitle: UILabel!  
 
-     @IBOutlet weak var JieVideoSubTitle: UILabel!  
 
-       
 
-     override func awakeFromNib() {  
 
-         super.awakeFromNib()  
 
-         
 
-     }  
 
-   
 
-     override func setSelected(selected: Bool, animated: Bool) {  
 
-         super.setSelected(selected, animated: animated)  
 
-           
 
-      
 
-     }  
 
-   
 
- }  
 
 
JieDetailViewController.swift
-   
 
- import UIKit  
 
-   
 
- class JieDetailViewController: UIViewController {  
 
-       
 
-   
 
-     @IBOutlet var big_video_img: UIImageView!  
 
-     
 
-     var detailItem: NSDictionary?  
 
-       
 
-       
 
-     func configureView() {  
 
-         if let detail : NSDictionary = self.detailItem {  
 
-             self.title = detail.objectForKey("video_title") as? String  
 
-             let url : String = detail.objectForKey("video_img") as String  
 
-             let dataImg : NSData = NSData(contentsOfURL: NSURL(string : url))  
 
-             self.big_video_img.image = UIImage(data: dataImg)  
 
-         }  
 
-     }  
 
-       
 
-     override func viewDidLoad() {  
 
-         super.viewDidLoad()  
 
-         configureView()  
 
-     }  
 
-   
 
-     override func didReceiveMemoryWarning() {  
 
-         super.didReceiveMemoryWarning()  
 
-         
 
-     }  
 
-   
 
-     
 
-     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {  
 
-          
 
-     }  
 
-   
 
- }  
 
 

 
 
 

 
 


 
源码地址:https://github.com/jwzhangjie/JieTableView