我正在擴展單擊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