0

スクリーンショットのようなアプリを作成しようとしています:

http://imgur.com/oC1yjUc

タップするとセルの下にコンテンツが表示される表ビューのように見えます。誰でもこれを行う方法を知っていますか。表示したいコンテンツを含むセルを作成し、テーブルが読み込まれたときにセルの高さを制限することができました。タップすると、高さが増加します。しかし、これは私が望む方法ではありません。また、表示されるコンテンツの高さは任意であるため、それに応じてセルのサイズを変更する必要があります。

おそらく、私が達成しようとしていることを行う別の方法がありますか?

任意の入力をいただければ幸いです。

編集: わかりました、これはある程度機能しますが、これには特定の問題があります: 1) 一部の行は前の行のデータを表示するだけです 2) セルを展開および折りたたむと、表示する必要があるときにコンテンツが変更されます/隠れる

私のコード:

    #import "ViewController.h"
    #import "Data.h"

    @interface ViewController ()

    @end

    @implementation ViewController {
        NSArray *data;
        NSInteger selectedIndex;
        NSIndexPath *selectedCellIndexPath;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.

        selectedIndex = -1;

        self.navigationItem.title = @"Test App";

        UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
        [[self navigationItem] setBackBarButtonItem:backButton];

        // Create Data array
        Data *data1 = [Data new];
        data1.text = @"Abhijit ipsum dolor sit amet, consectetur adipiscing elit.";
        data1.translation = @"AbhijitDE ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data2 = [Data new];
        data2.text = @"Anurag ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data2.translation = @"AnuragDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data3 = [Data new];
        data3.text = @"Chetan ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data3.translation = @"ChetanDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data4 = [Data new];
        data4.text = @"Eric ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data4.translation = @"EricDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data5 = [Data new];
        data5.text = @"Neha ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsumiraj dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data5.translation = @"NehaDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data6 = [Data new];
        data6.text = @"Nilesh ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data6.translation = @"NileshDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data7 = [Data new];
        data7.text = @"Niraj ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsumiraj dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data7.translation = @"NirajDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        data = [NSArray arrayWithObjects:data1, data2, data3, data4, data5, data6, data7, nil];
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return data.count;
    }

    // This just a convenience function to get the height of the label based on the comment text
    -(CGFloat)getLabelHeightForIndex:(NSString *)string
    {
        CGSize maximumSize = CGSizeMake(320, 10000);

        CGSize labelHeightSize = [string sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0f] constrainedToSize:maximumSize lineBreakMode:NSLineBreakByWordWrapping];

        return labelHeightSize.height + 10;

    }

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UILabel *mainLabel, *secondLabel;
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

            // First label
            mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 36.00)];
            mainLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
            mainLabel.textColor = [UIColor blackColor];
            mainLabel.backgroundColor = [UIColor clearColor];
            mainLabel.numberOfLines = 0;
            mainLabel.lineBreakMode = NSLineBreakByWordWrapping;
            // mainLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            // mainLabel.clipsToBounds = YES;
            [cell.contentView addSubview:mainLabel];

            // Second label
            secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 10.0, 320.0, 36.00)];
            secondLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
            secondLabel.textColor = [UIColor whiteColor];
            secondLabel.backgroundColor = [UIColor grayColor];
            secondLabel.numberOfLines = 0;
            secondLabel.lineBreakMode = NSLineBreakByWordWrapping;
            // secondLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            // secondLabel.clipsToBounds = YES;
            [cell.contentView addSubview:secondLabel];
        }

        // Get data for the current row
        Data *dataContent = [data objectAtIndex:indexPath.row];

        CGFloat dataTextHeight = [self getLabelHeightForIndex:dataContent.text];

        mainLabel.frame = CGRectMake(0.0, 0.0, 320.0, dataTextHeight);
        mainLabel.text = dataContent.text;

        CGFloat dataTranslationHeight = [self getLabelHeightForIndex:dataContent.translation];

        secondLabel.frame = CGRectMake(0.0, dataTextHeight + 10.00, 320.0, dataTranslationHeight);
        secondLabel.text = dataContent.translation;

        if(selectedIndex == indexPath.row)
        {
            secondLabel.hidden = YES;
        }
        else
        {
            secondLabel.hidden = YES;
        }

        return cell;
    }

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        // Get data for the current row
        Data *dataContent = [data objectAtIndex:indexPath.row];

        CGFloat dataTextHeight = [self getLabelHeightForIndex:dataContent.text];
        CGFloat dataTranslationHeight = [self getLabelHeightForIndex:dataContent.translation];

        if(selectedIndex == indexPath.row)
        {
            return (dataTextHeight + dataTranslationHeight) + 10;
        }
        else
        {
            return dataTextHeight;
        }
    }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // An expanded cell is clicked, minimize it
        if(selectedIndex == indexPath.row)
        {
            selectedIndex = -1;
            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

            return;
        }

        // If any previous cell is expanded, minimize it
        if(selectedIndex >= 0)
        {
            NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];
        }

        // Expand the currently expanded cell
        selectedIndex = indexPath.row;
        NSIndexPath *currentPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:currentPath] withRowAnimation:UITableViewRowAnimationFade];
    }

    @end
4

4 に答える 4

1

動的にサイズ設定された細胞は、お尻の痛みであり、それからいくつかの痛みです。StackOverflowにはいくつかの興味深い解決策が記載された質問がたくさんあるので、調べてみてください。

下面図に関する限り、HHPanningTableViewCellと呼ばれる優れたオープンソースプロジェクトがあり、調査する必要があります。私たちはいくつかのプロジェクトに使用しましたが、それでうまくいきます。残念ながら、いくつかのパフォーマンスの問題があります(プロジェクトに関する私の未解決の問題を参照してください)ので、必ずデバイスでテストしてください。

于 2013-02-05T13:50:55.727 に答える
0

テーブル ビュー デリゲートtableView:didSelectRowAtIndexPath:メソッドでは、insertRowsAtIndexPaths:withRowAnimation:およびdeleteRowsAtIndexPaths:withRowAnimation:メソッドを使用して、「ソース言語」セルがタップされたときに新しいセルを挿入し、挿入されたセルが「宛先言語」になります。ユーザーがもう一度タップすると、「宛先言語」セルが削除されます。どちらの方法でも、希望する公開アニメーションを指定できます。

于 2013-02-06T14:02:08.763 に答える
0

わかった。私はそれを考え出した。

誰かがそれを必要とする場合、これが私の更新されたコードです:

    #import "ViewController.h"
    #import "Data.h"

    @interface ViewController ()

    @end

    @implementation ViewController {
        NSArray *data;
        NSInteger selectedIndex;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.

        selectedIndex = -1;

        self.navigationItem.title = @"Test App";

        UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
        [[self navigationItem] setBackBarButtonItem:backButton];

        // Create Data array
        Data *data1 = [Data new];
        data1.text = @"Abhijit ipsum dolor sit amet, consectetur adipiscing elit.";
        data1.translation = @"AbhijitDE ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data2 = [Data new];
        data2.text = @"Anurag ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data2.translation = @"AnuragDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data3 = [Data new];
        data3.text = @"Chetan ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data3.translation = @"ChetanDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data4 = [Data new];
        data4.text = @"Eric ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data4.translation = @"EricDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data5 = [Data new];
        data5.text = @"Neha ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsumiraj dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data5.translation = @"NehaDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data6 = [Data new];
        data6.text = @"Nilesh ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data6.translation = @"NileshDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        Data *data7 = [Data new];
        data7.text = @"Niraj ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsumiraj dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
        data7.translation = @"NirajDE ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

        data = [NSArray arrayWithObjects:data1, data2, data3, data4, data5, data6, data7, nil];
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return data.count;
    }

    -(CGFloat)getLabelHeightForIndex:(NSString *)string
    {
        CGSize maximumSize = CGSizeMake(320, 10000);
        CGSize labelHeightSize = [string sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0f] constrainedToSize:maximumSize lineBreakMode:NSLineBreakByWordWrapping];

        return labelHeightSize.height + 10;
    }

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        static const int mainLabelTag = 1, secondLabelTag = 2;
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

            // First label
            UILabel *mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 36.00)];
            mainLabel.tag = mainLabelTag;
            mainLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
            mainLabel.textColor = [UIColor blackColor];
            mainLabel.backgroundColor = [UIColor clearColor];
            mainLabel.numberOfLines = 0;
            mainLabel.lineBreakMode = NSLineBreakByWordWrapping;
            mainLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            // mainLabel.clipsToBounds = YES;
            [cell.contentView addSubview:mainLabel];

            // Second label
            UILabel *secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 10.0, 320.0, 36.00)];
            secondLabel.tag = secondLabelTag;
            secondLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
            secondLabel.textColor = [UIColor whiteColor];
            secondLabel.backgroundColor = [UIColor grayColor];
            secondLabel.numberOfLines = 0;
            secondLabel.lineBreakMode = NSLineBreakByWordWrapping;
            secondLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            // secondLabel.clipsToBounds = YES;
            [cell.contentView addSubview:secondLabel];
        }

        // Get data for the current row
        Data *dataContent = [data objectAtIndex:indexPath.row];

        CGFloat dataTextHeight = [self getLabelHeightForIndex:dataContent.text];

        UILabel *mainLabel = [cell.contentView viewWithTag:mainLabelTag];
        CGRect mainLabelFrame = mainLabel.frame;
        mainLabel.frame = CGRectMake(0.0, 0.0, mainLabelFrame.size.width, dataTextHeight);
        mainLabel.text = dataContent.text;

        CGFloat dataTranslationHeight = [self getLabelHeightForIndex:dataContent.translation];

        UILabel *secondLabel = [cell.contentView viewWithTag:secondLabelTag];
        CGRect secondLabelFrame = mainLabel.frame;
        secondLabel.frame = CGRectMake(0.0, dataTextHeight + 10.00, secondLabelFrame.size.width, dataTranslationHeight);
        secondLabel.text = dataContent.translation;

        if(selectedIndex == indexPath.row)
        {
            secondLabel.hidden = NO;
        }
        else
        {
            secondLabel.hidden = YES;
        }

        return cell;
    }

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        // Get data for the current row
        Data *dataContent = [data objectAtIndex:indexPath.row];
        CGFloat dataTextHeight = [self getLabelHeightForIndex:dataContent.text];
        CGFloat dataTranslationHeight = [self getLabelHeightForIndex:dataContent.translation];

        if(selectedIndex == indexPath.row)
        {
            return (dataTextHeight + dataTranslationHeight) + 10;
        }
        else
        {
            return dataTextHeight;
        }
    }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
        // An expanded cell is clicked, minimize it
        if(selectedIndex == indexPath.row)
        {
            selectedIndex = -1;
            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            return;
        }

        // If any previous cell is expanded, minimize it
        if(selectedIndex > -1)
        {
            NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
            selectedIndex = -1;
            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        }

        // Expand the currently expanded cell
        selectedIndex = indexPath.row;
        NSIndexPath *currentPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:currentPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }

    @end
于 2013-02-15T06:19:47.470 に答える
-1

たぶん次のようなものを試してください

cell.clipsToBounds = YES;
cell.autoresizingMask = UIViewAutoresizingFlexibleHeight;

?

于 2013-02-05T13:32:14.647 に答える