2011-10-18 11 views
0

私は、テーブルセル(パルスリーダのようなもの)の内部に水平テーブルビューを埋め込んでいます。面白いのは、dequeueReusableCellWithIdentifier:が、私が何もせずに、埋め込みテーブルビューのオフセットを正しく記憶しているようだということです。しかしdequeueReusableCellWithIdentifier:セルの状態を記憶する

ファースト(予想)

を「思い出し」するには、2つのフレーバーがあり、私は100個のセクションとセクションごとに1行を持つテーブルを作成します。各セル(各セクション)は、100行と1セクションを持つように強制された埋め込みテーブルビューを取得します。私は垂直のテーブルビューをスクロールすると、細胞が再利用されている(dequeueReusableCellWithIdentifier:

VerticalTableViewCell *cell = (VerticalTableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

後の細胞のインスタンス名を見ることで確認され、私は右に最初のテーブルビューセルの埋め込まれたテーブルビューをスクロールすると、10.5細胞を言います、私は、垂直テーブルビューでカップルのセルをスクロールすると、再利用されたテーブルのセルは、それらの10.5セルによってオフセットされた埋め込まれたテーブルビューを持っています。私は今7行目の埋め込みテーブルビュー(これは再利用のために1行目と同じ埋め込みテーブルビューです)をスライドさせて20の位置にスライドさせると、埋め込まれた垂直テーブルビューの一番上に移動します私が元々10.5に移動していたテーブルビューは、今は20になっています。再び、期待されるテーブル細胞は同じです。ちょうど再利用。

第二(希望が、それがどのように動作するか分からない)

今私だけではなく、セルに

[cell.textLabel setText:[NSString stringWithFormat: @"here: %d", indexPath.row]]; 

を印刷する(私の実際のデータを入力してください。

今、突然、私の埋め込みテーブルのビューDO私はもう一度、セルが再利用されていることを確認します(上記と同じ方法です)。 (10.5の位置に)、7行目までスクロールすると、7行目が開始点になります。最初の行を表示に戻すと、それは私が残した場所です。

これは、Xcode 4.2とiOS 5.0を使用しています。 dequeueReusableCellWithIdentifier:のスマートなことはありますか?古い学校(前のiOS 5.0)で

、私は何が起こっているか確認するために、ロジックの

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

if (cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 
} 

ビットをチェックしているだろうが、ストーリーボードでそれらはもはや必要ありません。

異なる動作をする2つのサンプルプロジェクトは大きなものですが、表示する関連するコードがある場合はお知らせください。

あまりにも漠然として申し訳ありませんが、私はちょうどこれらのテーブルビューのメモリ管理について何が起こっているのか正確に把握しようとしています。

すべての接続はIBOutletsを経由し、StoryBoardで行われます。

ありがとうございます!

まず垂直のテーブルビューコントローラ

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
//#warning Potentially incomplete method implementation. 
// Return the number of sections. 
return 100; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
//#warning Incomplete method implementation. 
// Return the number of rows in the section. 
return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"PlayerCell"; 

PlayerCell *cell = (PlayerCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 


// Configure the cell... 

cell.games = [NSMutableArray arrayWithCapacity:1]; 
if(indexPath.section <40){ 
    //[cell.textLabel setText:[NSString stringWithFormat:@"h343: %d", indexPath.section]]; 
} 

CGAffineTransform rotateTable = CGAffineTransformMakeRotation(-M_PI_2); 
cell.htv.transform = rotateTable; 
cell.htv.frame = CGRectMake(0, 0, 320, 120); 

return cell; 
} 

まず水平テーブルビューのデリゲート/データソース

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

// Return the number of sections. 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

// Return the number of rows in the section. 
return 100; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 

//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

// Configure the cell... 

CGAffineTransform rotateImage = CGAffineTransformMakeRotation(M_PI_2); 
cell.transform = rotateImage; 

//[cell.myLabel setText:[NSString stringWithFormat:@"%d", indexPath.row]]; 

[cell.textLabel setText:[NSString stringWithFormat: @"here: %d", indexPath.row]]; 
return cell; 
} 

第2の垂直表ビューコントローラ

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

// Return the number of sections. 
return [self.leagues count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

// Return the number of rows in the section. 
return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 
static NSString *CellIdentifier = @"VerticalTableViewCell"; 




VerticalTableViewCell *cell = (VerticalTableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

NSLog(@"Cell: %@ for index: %d", cell, indexPath.section); 


cell.games = [self.leagues objectAtIndex:indexPath.section]; 

CGAffineTransform rotateTable = CGAffineTransformMakeRotation(-M_PI_2); 
cell.horizontalTableView.transform = rotateTable; 
cell.horizontalTableView.frame = CGRectMake(0, 0, 320, 120); 
// Configure the cell... 



cell.selectionStyle = UITableViewCellSelectionStyleNone; 

cell.section = indexPath.section; 

return cell; 
} 

第2の水平テーブルビューのデリゲート/データソース

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

// Return the number of sections. 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

// Return the number of rows in the section. 
return [self.games count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"HorizontalTableViewCell"; 

//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
GameTableCell *cell = (GameTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

// Configure the cell... 

CGAffineTransform rotateImage = CGAffineTransformMakeRotation(M_PI_2); 
cell.transform = rotateImage; 

//[cell.myLabel setText:[NSString stringWithFormat:@"%d", indexPath.row]]; 

NSDictionary *game = [self.games objectAtIndex:indexPath.row]; 
[cell.homeTeamLogo setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[game objectForKey:@"LogoImage_HomeTeam"]]]]; 
[cell.visitingTeamLogo setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[game objectForKey:@"LogoImage_VisitingTeam"]]]]; 
[cell.homeTeamName setText:[NSString stringWithFormat:@"%@", [game objectForKey:@"AbbreviatedName_HomeTeam"]]]; 
[cell.visitingTeamName setText:[NSString stringWithFormat:@"%@", [game objectForKey:@"AbbreviatedName_VisitingTeam"]]]; 

NSDictionary *gameTime = [game objectForKey:@"GameTime"]; 
NSString *minutes = [NSString stringWithFormat:@"%@", [gameTime objectForKey:@"Minutes"]]; 
if([minutes length]==1){ 
    minutes = @"00"; 
} 
NSString *timeOfGame = [NSString stringWithFormat:@"%@:%@",[gameTime objectForKey:@"Hours"], minutes]; 

[cell.gameTime setText:timeOfGame]; 

return cell; 
} 

答えて

0

私のせい。

埋め込みテーブルビューの状態を保存していました。

FYI:tableView.contentOffsetを使用していました(これは後で行う必要がある場合に備えて)。

おっと。

関連する問題