[英]how to add a custom view in the selected row in 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];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%ld",(long)indexPath.row); //
str=[appdelegate.name objectAtIndex:indexPath.row];
DetailViewController *dvc = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; //DetailViewController is your view
[self.navigationController pushViewController:dvc animated:YES];
}
我沒有試過這個,但它可能會工作讓我知道它是否有效。
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableview cellForRowAtIndexPath: indexpath];
[cell.contentView addSubView: yourviewObject];
cell.bounds.size.height = yourViewObject.bounds.size.height + 10.0;
}
看到這個用於在uitableview的選定行中添加自定義視圖
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.