1

カスタムの高さを持つ 2 つのプロトタイプ セルを持つ UITableViewController があります。1 つの高さは 187 ポイントで、もう 1 つの高さは 140 ポイントです。テーブルビューのデフォルトの行の高さは ser to 187 です。

私の cellForRowAtIndexPath は次のようになります。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (indexPath.section == 0) {
        MyListingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyListingCell"];
        [cell initWithListing:[self.listings objectAtIndex:indexPath.row]];
        return cell;
    } else {
        return [tableView dequeueReusableCellWithIdentifier:@"AddMyListingCell"];
    }
}

そして、次のような一致する heightForRowAtIndexPath があります。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyListingCell"];
        return cell.frame.size.height;
    } else {

        //if no listings exist, make the cell full-screen height
        if (self.listings.count == 0) {   
            return tableView.frame.size.height;
        } else {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AddMyListingCell"];
            return cell.frame.size.height;
        }
    }
}

コードを実行すると、セルの高さが正しく表示されます。それぞれ187と140。

ただし、大きいセルのサイズを 213 ポイントに変更したいと考えています。これを行うには、カスタム テーブル セルの高さを 213 に変更します。問題は、(XCode 6 を使用して) コードを実行すると、テーブル セルの高さが 187 のままになることです。

デフォルトの tableview rowheight プロパティも 213 に変更しようとしましたが、それでも 187 になります。実際、ストーリーボード (テキストとして) を見ると、187 についての言及はどこにもありません。しかし、XCode は以前の値を記憶しているようです。

クリーニング、ディープ クリーニング、xcode の再起動、携帯電話からのアプリの削除、デバッグ製品の削除を試しました。187を忘れるわけにはいきません。

これは XCode 6 のバグでしょうか? XCode 5 では、これは起こりません (証明済み)。カスタム セルの高さは XCode 5 で正常に機能していましたが、この問題は XCode 6 をインストールした翌日に発生しました。

試してみるべきことについてのアドバイスや、私が夢中になっていないことの確認を手伝ってくれる人はいますか。

4

1 に答える 1

1

heightForRowAtIndexPathBEFORE と呼ばれるcellForRowAtIndexPathため、セルを参照して高さを取得するために使用することはできません。次のログ行と結果を含む次のコードを見てください。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"CELL");
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

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

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"HEIGHT");
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    NSLog(@"%@", cell);
    return cell.frame.size.height;
}

その結果、次のようになります。

2014-09-23 09:55:05.114 NewTesting[54040:60b] HEIGHT
2014-09-23 09:55:05.114 NewTesting[54040:60b] (null)
2014-09-23 09:55:05.115 NewTesting[54040:60b] HEIGHT
2014-09-23 09:55:05.115 NewTesting[54040:60b] (null)
2014-09-23 09:55:05.115 NewTesting[54040:60b] HEIGHT
2014-09-23 09:55:05.116 NewTesting[54040:60b] (null)
2014-09-23 09:55:05.116 NewTesting[54040:60b] HEIGHT
2014-09-23 09:55:05.116 NewTesting[54040:60b] (null)
2014-09-23 09:55:05.117 NewTesting[54040:60b] CELL
2014-09-23 09:55:05.118 NewTesting[54040:60b] CELL
2014-09-23 09:55:05.119 NewTesting[54040:60b] CELL
2014-09-23 09:55:05.120 NewTesting[54040:60b] CELL

それを念頭に置いて、あなたが使用している方法は決して機能しません。

次のようなもっと単純なことを試しましたか(個人的には定数を使用しますが)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return indexPath.section == 0 ? 213 : 140;
}

これは、最初のセクションのすべてのセルの高さが 213 で、他のセクションの高さが 140 であると仮定しているため、これは正しくない可能性があります。

最終的に、あなたがやりたいことを行うための最良の方法は、本質的にデータソースにその特定のセルのタイプindexPath、したがってセルの高さを尋ねることだと思います。

于 2014-09-23T14:03:53.880 に答える