Write a simple uitableview to create, after a few previous installments, then create a common control is pretty simple OH
class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate, nsurlconnectiondatadelegate { var dataarray = nsmutablearray () var tableView: UITableView? override func viewdidload () { Super.viewdidload () // Do any additional setup after loading the view, typically from a nib. self.title = "SWH" for var i = 0; i < 6; i++ { Self.dataArray.addObject ("row\ (i)") &NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; } self.tableview = uitableview (frame: self.view.bounds, style: . Plain) self.tableview!. delegate = self self.tableview!. Datasource = self self.view.addsubview (Self.tableView !) } func tableview (tableView: Uitableview, numberofrowsinsection section: int) -> Int { return self.dataArray.count } func tableview (Tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cellidentify = "Mycellidentify" var cell = tableview.dequeuereusablecellwithidentifier (cellIdentify) as? UITableViewCell if (Cell == nil) { cell = uitableviewcell (Style : . default, reuseidentifier: cellidentify) } var string = self.dataarray.objectatindex (IndexPath.row) as? string cell?. Textlabel?. text = string return cell! } func tableview (Tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { } override func didreceivememorywarning () { super.didreceivememorywarning () // Dispose of any resources that can be recreated. }}
Then we call the O-C code in swift, so that we can take advantage of a lot of O-c's three-way open Source Library.
We create a new OC class file in the project, it will prompt to establish a bridge with Swift, choose Yes, will create a new file, the name is "project name-bridging-header.h" file, inside the import you want to call the O-c header file will be OK!
Then the introduction of the O-C call Swift code, it's not very common to feel this
is to directly import the header file, the name is "project name-swift.h", of course, the name is not necessarily correct, we can go to see the relevant product Module name, and then replace the project name.
Well, basically this is it, in fact, we can swift.h inside to see the relevant code conversion OH
This article is from the "Neusoft iOS Alumni Group Technology Blog" blog, please be sure to keep this source http://neusoftios.blog.51cto.com/9977509/1674955
Swift article fifth: Uitableview,oc and Swift Mutual tuning