initWithFrame:reuseIdentifier:

initWithFrame:reuseIdentifier:

Initializes and returns a table-view cell object.

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier

Parameters
frame

The frame rectangle of the cell. Because the table view automatically positions the cell and makes it the optimal size, you can pass in CGRectZero in most cases. However, if you have a custom cell with multiple subviews, each with its own autoresizing mask, you must specify a non-zero frame rectangle; this allows the table view to position the subviews automatically as the cell changes size.

reuseIdentifier

A string used to identify the cell object if it is to be reused for drawing multiple rows of a table view. Pass nil if the cell object is not to be reused.

Return Value

An initialized UITableViewCell object or nil if the object could not be created.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
您好,可以使用以下代码实现: 1. 在UITableViewCell的初始化方法中,创建YYLabel并添加到cell.contentView中: ``` - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { YYLabel *label = [[YYLabel alloc] initWithFrame:CGRectZero]; [self.contentView addSubview:label]; self.yyLabel = label; } return self; } ``` 2. 在设置UITableViewCell的数据源方法中,设置YYLabel的frame和内容: ``` - (void)setModel:(Model *)model { _model = model; self.yyLabel.frame = CGRectMake(10, 10, self.contentView.bounds.size.width - 20, model.textLayout.textBoundingSize.height); self.yyLabel.attributedText = model.textLayout.text; } ``` 3. 在NSMutableAttributedString中插入attachment时,可以使用YYTextAttachment对象,并将UITextView添加到attachment中: ``` YYTextAttachment *attachment = [YYTextAttachment new]; attachment.content = textView; attachment.contentMode = UIViewContentModeScaleAspectFit; attachment.contentInsets = UIEdgeInsetsMake(, , , ); NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment]; [attributedString insertAttributedString:attachmentString atIndex:insertIndex]; ``` 4. 处理UITextView与TableView滚动冲突的问题,可以在UITextView的父视图中重写以下方法: ``` - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { if ([self pointInside:point withEvent:event]) { self.superview.userInteractionEnabled = NO; } else { self.superview.userInteractionEnabled = YES; } return [super hitTest:point withEvent:event]; } - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { self.superview.userInteractionEnabled = YES; [super touchesEnded:touches withEvent:event]; } ``` 希望以上代码对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值