前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS对象实例化

iOS对象实例化

作者头像
码客说
发布2019-10-22 14:08:14
1.6K0
发布2019-10-22 14:08:14
举报
文章被收录于专栏:码客

实例化TableCell

在设置delegate之前注册xib

Swift

代码语言:javascript
复制
self.tableView.registerNib(UINib.init(nibName: "ImageLabelTableViewCell", bundle: nil), forCellReuseIdentifier: "ImageLabelTableViewCell");

Swift3

代码语言:javascript
复制
self.tableView.register(UINib.init(nibName: "IndexTableViewCell", bundle: nil), forCellReuseIdentifier: "IndexTableViewCell");

OC

代码语言:javascript
复制
[self.tableView registerNib:[UINib nibWithNibName:@"ImageLabelTableViewCell" bundle:nil] forCellReuseIdentifier:@"ImageLabelTableViewCell"];

实例化Cell

Swift

代码语言:javascript
复制
let  cell = tableView.dequeueReusableCellWithIdentifier("ImageLabelTableViewCell", forIndexPath: indexPath) as! ImageLabelTableViewCell;

Swift3

代码语言:javascript
复制
let  cell = tableView.dequeueReusableCell(withIdentifier: "IndexTableViewCell", for: indexPath) as! IndexTableViewCell;

OC

代码语言:javascript
复制
ImageLabelTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ImageLabelTableViewCell" forIndexPath:indexPath];

如果用的storybord中的tableview的cell直接用dequeueReusableCellWithIdentifier方法就行了 注意dequeueReusableCellWithIdentifier方法是从已经实例化的cell中查找id为textLeftCell的对象并进行拷贝

实例化视图控制器

从storyboard中

Swift

代码语言:javascript
复制
self.storyboard?.instantiateViewControllerWithIdentifier("renwuMy") as! RenwuMyViewController;

根据xib实例化控制器

代码语言:javascript
复制
RenwuMyViewController * renwuMy Controller = [[RenwuMyViewController alloc] initWithNibName:@"RenwuMyViewController" bundle:nil];

实例化UICollectionCell

在设置delegate之前注册xib

Swift

代码语言:javascript
复制
self.collectionView.registerNib(UINib.init(nibName: "MyCell", bundle: nil), forCellWithReuseIdentifier: "MyCell");

Objc

代码语言:javascript
复制
[self.collectionView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellWithReuseIdentifier:@"MyCell"];

实例化Cell

Swift

代码语言:javascript
复制
let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("MyCell", forIndexPath: indexPath) as! MyCell;

OC

代码语言:javascript
复制
MyCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];

从xib中实例化对象

代码语言:javascript
复制
let cell = NSBundle.mainBundle().loadNibNamed("FuImageLabelTableViewCell", owner: self, options: nil).first as! FuImageLabelTableViewCell;
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-08-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 实例化TableCell
  • 实例化视图控制器
  • 根据xib实例化控制器
  • 实例化UICollectionCell
  • 从xib中实例化对象
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档