2014-08-28 89 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

相關問題