2014-08-28 86 views
0

我正在扩展单击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; 

} 
+0

你展开之后重装电池? – 2014-08-28 14:00:28

+0

是的我正在重新加载单元格 – iSD 2014-08-28 14:00:54

+0

你在哪里声明了isExpanded,backgroundView,container和container_scrollView对象?他们是伊娃?如果你有更多的单元格,当你调用[cell.contentView addSubview:backgroundView]; backgroundView将从之前的单元格中移除。 – 2014-08-28 14:06:30

回答

0

你应该考虑在你的故事板两种不同的细胞或2个厦门国际银行文件,各有其correspoding cellidentifier。一个是你的正常细胞,另一个是扩大的细胞。然后,每当用户点击一个正常单元格时,应该用第二个类型单元格(扩展单元格)“替换”(重绘)该特定单元格。

UPDATE

为了执行,你可以使用任何这些方法的细胞的更新。 more here

reloadData 
reloadRowsAtIndexPaths:withRowAnimation: 
reloadSections:withRowAnimation: 

这些将导致你的一些表视图数据源委托方法再次调用,那么就应该使用一些逻辑来决定提请哪种细胞。快速草案:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *cellIdentifier; 

    // Here you should implement your custom logic to check if you want a basic or expanded cell. 
    if (IWantBasicCell) { 
     cellIdentifier = @"basicCell"; 
    } else { 
     cellIdentifier = @"expandedCell" 
    } 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    [cell myCustomLoadInformationMethod:myCustomData]; 
    return cell; 

}

+0

好的..我当前的单元格也依赖于webservice的数组。我如何实现单元更换? – iSD 2014-08-28 14:09:22

+0

刚刚更新了我的答案,希望有所帮助 – CoderPug 2014-08-28 14:25:52

相关问题