Swift article fifth: Uitableview,oc and Swift Mutual tuning

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.