0

通常、テーブルにデータをリロードする関数 reloaddata を使用しますが、別のタイプの UITableViewCell に変更したい場合はどうすればよいですか?

基本的に私は動的に呼び出すのが好きです

 -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

これにより、さまざまなタイプの細胞をロードできます。

4

3 に答える 3

0

NSStringプロパティを設定して、それをdequeueReusableCellWithIdentifier:パラメータとして使用しようとしましたか。次にreloadData、セルをスワップアウトする可能性がありますか?

これを自分で試したわけではありません-ただの考えです。

于 2012-06-29T02:04:09.407 に答える
0

さまざまなセル タイプの typedef を定義します。

typedef enum {
    kTableCellType1,
    kTableCellType2
} TableCellType;

次に、新しい TableCellType を使用するクラス インスタンス変数を定義します。

@interface MyTableViewController ()
{
    TableCellType _tableCellType;
}
@end

で、このviewDidLoadivar を初期化します。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // do all of your other initialization

    _tableCellType = kTableCellType1;
}

次に、cellForRowAtIndexPath使用するセルの種類を確認できます。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_tableCellType == kTableCellType1)
    {
        // build first table cell type
    }
    else if (_tableCellType == kTableCellType2)
    {
        // build the other table cell type
    }
}

最後に、セルを変更する場合は、ivar を変更してからデータをリロードします。

_tableCellType = kTableCellType2;
[self.tableView reloadData]; // or reloadRowsAtIndexPaths or reloadSections
于 2012-06-29T03:35:00.827 に答える
0

試す

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

リロードするインデックスの配列を渡します。cellForRowAtIndexPath コールバックが呼び出されます。

于 2012-06-29T02:35:57.127 に答える