我正在扩展单击UITableView单元格。当单元展开时,我必须将UIView加载到它中。我的问题是,我能够在少数情况下看到UIView,有时它不显示? UIView将被加载到每个扩展单元中。UITableView单元的扩展视图不显示子视图?
扩张是这样完成的: -
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat kExpandedCellHeight =300;
CGFloat normalCellHeight = 94;
if ([self.expandedCells containsObject:indexPath]) {
return kExpandedCellHeight;
}else{
return normalCellHeight;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"Cell";
ListCell *cell =(ListCell*) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ListCell" owner:self options:nil];
cell = nibs[0];
}
cell.Name.text = [[nameArray objectAtIndex:indexPath.row]valueForKey:@"opName"];
if (isExpanded) {
backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 95, 320,205)];
[backgroundView setBackgroundColor:[UIColor colorWithRed:(235/255) green:(235/255) blue:(235/255) alpha:0.1]];
[cell.contentView addSubview:backgroundView];
container = [[UIView alloc]initWithFrame:CGRectMake(40, 67, 240, 120)];
container.backgroundColor = [UIColor whiteColor];
//I am adding buttons to this scrollview after webservice response,once buttons are loaded I am trying to load the above container on the background view.
container_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(20, 5, 220, 110)];
[container_scrollView setBackgroundColor:[UIColor whiteColor]];
[container addSubview:container_scrollView];
}
return cell;
}
现在我得到来自webservice.Buttons响应添加为well.However我可以看到有时装载容器视图,有时不show.What必须是原因?什么导致了这种行为?
这是我如何将容器加载到背景视图上。
//After container is loaded with buttons.
if(backgroundView){
[backgroundView addsubView:container];
}
宣言东西:
@interface ListViewController()
{
UIView *backgroundView;//Used in expanded cell.
UIView *container;
BOOL isExpanded; //I set this to NO in viewDidLoad initially.
UIScrollView *container_scrollView;
}
你展开之后重装电池? – 2014-08-28 14:00:28
是的我正在重新加载单元格 – iSD 2014-08-28 14:00:54
你在哪里声明了isExpanded,backgroundView,container和container_scrollView对象?他们是伊娃?如果你有更多的单元格,当你调用[cell.contentView addSubview:backgroundView]; backgroundView将从之前的单元格中移除。 – 2014-08-28 14:06:30