1

コードのみを使用して(IBを使用せずに)UIViewでUITableViewを作成します

 m_tableData = [[UITableView alloc] init];
 m_tableData.dataSource = self; 
 m_tableData.delegate = self;   
 [self addSubview:m_tableData];

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     NSLog(@"%d", [arrPanelListImg count]);
     return [arrPanelListImg count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"kCell"];

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


        NSLog(@"%d", indexPath.row);

    }

return cell;

}

そして、ログ画面に表示されます

numberOfRowsInSection:メソッドは18を返します。cellForRowAtIndexPath:メソッドは、9回実行するだけです(画面に収まります)。

そして、私は自分のコードに何も奇妙なことを発見しませんでした。したがって、この場合、誰かが私に何か提案をします。よろしくお願いします。

4

2 に答える 2

0

UITableViewinitWithFrame:style:メソッドを使用する必要があります。これは、UITableViewクラスの指定された初期化子です。

于 2012-09-18T18:55:22.553 に答える
0

ということですか

m_tableData = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];

それに変更すると、元の結果と何も変わりません。本当に奇妙です。このエラーを目にしたのはこれが初めてで、まだ解決策がありません。

編集: - チェック条件 cell == nil を削除するだけで正しく動作します。

于 2012-09-19T16:12:02.150 に答える