簡體   English   中英

如何展開表格視圖單元格?

[英]How to expand my table view cell?

使用此代碼擴展表格視圖單元格,但對我而言不起作用。我知道此代碼中存在一些錯誤,可幫助我查找。

![selectindex = -1;

    // Do any additional setup after loading the view.

}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  \[Arr_lbl count\];
}
#pragma mark table cell creating and loading the data
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AntzclubCell *cell=\[tableView dequeueReusableCellWithIdentifier:@"Antz"\];
    cell.img_antzClub.image=\[UIImage imageNamed:\[Arr_img objectAtIndex:indexPath.row\]\];
    cell.lbl_antzClub.text=\[Arr_lbl objectAtIndex:indexPath.row\];
    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
    cell.backgroundColor=\[UIColor blackColor\];
    return  cell;
}
#pragma mark expanding height
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(selectindex==indexPath.row){
        return 400;
    }
    else{
        return 132;
    }

}
#pragma mark user selecting option
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==selectindex) {

        selectindex=-1;
        \[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
        return;
    }
        if(selectindex !=-1)
        {
            NSIndexPath *prepath=\[NSIndexPath indexPathForRow:selectindex inSection:0\];
            selectindex=indexPath.row;
            \[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:prepath\] withRowAnimation:UITableViewRowAnimationLeft\];
        }
        selectindex=indexPath.row;
        \[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
    }]

在此處輸入圖片說明 此圖像是我的輸出,而我單擊與其他數據不合並的單元格。

根據您要支持的iOS版本,答案可能有所不同,但是您似乎沒有實現heightForRowAtIndexPath:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM