私はまだ iPhone SDK に精通している途中です。
これは私がやろうとしていることです:
UIScrollView があり、各スクロール ビューには UITableView があり、カスタム UITableViewCell を実装しました。
望ましい機能は、最初は選択がなく、ユーザーが行を選択してスクロールし、次のスクロール ビューで別の選択を行って続行することです。ユーザーが後で選択を変更できるように、選択を維持したい。
ただし、私の場合、最初と2番目のUITableViewは問題なく、選択された行は選択されたままですが、3番目のUITableViewでは、最初のUITableViewと同じ行が「すでに」選択されています。選択したものを見たくありません。
私は自分が愚かなことをしていることを知っていますが、何を理解することはできません。どんな助けでも本当に感謝しています。
ありがとう、エイミー
関連するデータ ソースとデリゲート メソッドを次に示します。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
static NSString * ChoiceTableCellIdentifier = @"ChoiceTableCellIdentifier";
choiceTableCell = (ChoiceTableCell *)[tableView dequeueReusableCellWithIdentifier:ChoiceTableCellIdentifier];
if( choiceTableCell == nil )
{
choiceTableCell = [[[ChoiceTableCell alloc]
initWithFrame:CGRectZero
reuseIdentifier:ChoiceTableCellIdentifier] autorelease];
}
return choiceTableCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
int newRow = [indexPath row];
int oldRow = [lastIndexPath row];
if ( (newRow != oldRow) || (newRow == 0) )
{
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
UIImageView *indicatorN = (UIImageView *)[newCell.contentView viewWithTag:SELECTION_INDICATOR_TAG_1];
indicatorN.image = [UIImage imageNamed:@"selected.png"];
newCell.backgroundView.backgroundColor = [UIColor clearColor];
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
UIImageView *indicatorO = (UIImageView *)[oldCell.contentView viewWithTag:SELECTION_INDICATOR_TAG_1];
indicatorO.image = [UIImage imageNamed:@"notSelected.png"];
oldCell.backgroundView.backgroundColor = [UIColor clearColor];
lastIndexPath = indexPath;
}
}