我是編程新手,在這方面掙扎。 如何在UITableView的選定行中添加自定義視圖?如何在UITableView的選定行中添加自定義視圖?
所有其他行不應受到影響。新視圖應該出現在點擊行的位置。視圖可以有更大的尺寸。 謝謝。
我是編程新手,在這方面掙扎。 如何在UITableView的選定行中添加自定義視圖?如何在UITableView的選定行中添加自定義視圖?
所有其他行不應受到影響。新視圖應該出現在點擊行的位置。視圖可以有更大的尺寸。 謝謝。
可以在rowDidSelect委託方法添加新的觀點,
- (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];
}
的大小當我點擊一些其它行,子視圖出現在先前點擊的行上。這是爲什麼? – nitz19arg 2013-05-14 11:48:26
請參閱編輯 – 2013-05-14 11:55:02
看到了添加自定義視圖中的UITableView中選擇行
How to add a content view on UITAbleViewCell when a row is selected?
- (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;
}
- (CGFloat的)的tableView:(UITableView的*)的tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 使用這種方法來改變使用上述代碼,小區 – Bala 2013-05-14 11:25:40