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

前端之家收集整理的这篇文章主要介绍了ios – 如何在UITableView的选定行中添加自定义视图?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是编程的新手,并在这方面苦苦挣扎.
如何在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];
}

猜你在找的Xcode相关文章