加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 如何在UITableView的选定行中添加自定义视图?

发布时间:2020-12-14 17:12:17 所属栏目:百科 来源:网络整理
导读:我是编程的新手,并在这方面苦苦挣扎. 如何在UITableView中的选定行中添加自定义视图? 所有其他行不应受到影响.新视图应出现在单击行的位置.视图可以有更大的尺寸. 谢谢. 解决方法 您可以在rowDidSelect Delegate方法中添加新视图, - (void)tableView:(UITab
我是编程的新手,并在这方面苦苦挣扎.
如何在UITableView中的选定行中添加自定义视图?

所有其他行不应受到影响.新视图应出现在单击行的位置.视图可以有更大的尺寸.
谢谢.

解决方法

您可以在rowDidSelect Delegate方法中添加新视图,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(10.0f,10.0f,100.0f,30.0f)];
[myView setTag:-1];

[cell addSubview:myView];

}

同样实现DidDeselectRowatindexpath

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

UIView *myView = [cell viewWithTag:-1];

[myView removeFromSuperview];
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读