swift篇第五期:UITableView,OC与Swift互调
发布时间:2020-12-14 02:01:09 所属栏目:百科 来源:网络整理
导读:先写一个UITableView的简单创建吧,经过前面几期的内容,那么创建一个常用的控件也是蛮简单的哦 classViewController:UIViewController,UITableViewDataSource,UITableViewDelegate,NSURLConnectionDataDelegate{vardataArray=NSMutableArray()vartableView:
先写一个UITableView的简单创建吧,经过前面几期的内容,那么创建一个常用的控件也是蛮简单的哦 classViewController:UIViewController,UITableViewDataSource,UITableViewDelegate,NSURLConnectionDataDelegate{ vardataArray=NSMutableArray() vartableView:UITableView? overridefuncviewDidLoad(){ super.viewDidLoad() //Doanyadditionalsetupafterloadingtheview,typicallyfromanib. self.title="swh" forvari=0;i<6;i++{ self.dataArray.addObject("row(i)") } self.tableView=UITableView(frame:self.view.bounds,style:.Plain) self.tableView!.delegate=self self.tableView!.dataSource=self self.view.addSubview(self.tableView!) } functableView(tableView:UITableView,numberOfRowsInSectionsection:Int)->Int{ returnself.dataArray.count } functableView(tableView:UITableView,cellForRowAtIndexPathindexPath:NSIndexPath)->UITableViewCell{ letcellIdentify="myCellIdentify" varcell=tableView.dequeueReusableCellWithIdentifier(cellIdentify)as?UITableViewCell if(cell==nil){ cell=UITableViewCell(style:.Default,reuseIdentifier:cellIdentify) } varstring=self.dataArray.objectAtIndex(indexPath.row)as?String cell?.textLabel?.text=string returncell! } functableView(tableView:UITableView,didSelectRowAtIndexPathindexPath:NSIndexPath){ } overridefuncdidReceiveMemoryWarning(){ super.didReceiveMemoryWarning() //DispoSEOfanyresourcesthatcanberecreated. } } 然后就是在Swift里面调用O-C代码,这样有利于我们可以利用很多O-C的三方开源库哦 我们在工程中新创建一个OC类文件,它会提示是否建立与Swift的桥接,选择YES后,就会新创建一个文件,名字是“工程名-Bridging-Header.h”的文件,在里面导入你想要调用的O-C头文件就可以了哦 然后是介绍O-C调用Swift代码,感觉这个并不是很常用哦 就是直接导入头文件,名字是“工程名-Swift.h”,当然了,名字不一定正确,我们可以去看看设置里面相关的product Module Name,然后替换工程名字就可以了哦 好啦,基本就是这些吧,其实我们可以在swift.h里面去看一下相关的代码转换哦 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 认真做 flex + spring + blazeDS + google app JDO 分页.每
- ImageView中XML属性src和background区别
- iphone app beta测试人员是否需要开发人员的许可证?
- xml – 通过cURL向Google电子表格添加一行 – 必填字段错误
- Swift retrieved by calling -dequeueReusableSupplementar
- 使用指针修改字符串时会发生分段故障?
- c – 如何实验垃圾收集?
- lazarus中建立空sqlite数据库
- c# – Google Contacts API – 获取访问令牌(oauth)后
- VB6.0中没有ADO控件该如何办???