0

私はまだiPhone SDKについて知り合っています。UITableViewCellの選択はすべてのセルにとどまります!

これは私が何をしようとしていますものです:

私はUIScrollViewのを持っており、各スクロールビューがのUITableViewを持っていると私は、カスタムのUITableViewCellを実装しました。

最初に希望の機能が選択されていない場合、ユーザーは行を選択してスクロールし、次のスクロール・ビューで別の選択を行い続けます。選択肢を残しておきたいので、ユーザーは後で選択項目を変更することができます。

私のケースでは何が起きています - 最初と2番目のUITableViewsは問題ありません、選択された行が選択されたままになりますが、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; 
} 
} 


 

答えて

2

イメージ「selected.png」を持つセルを再利用しています。あなたが「選択」か、あなたの最後の選択を依存するあなたのセルを「選択解除」する必要がcellForRowAtIndexPathメソッドで 。つまり、indexPathがlastIndexPathと等しい場合は、背景を "selected.png"、それ以外の場合は "noSelected.png"にする必要があります。 セルを再利用すると、セルは以前の状態を保持するため、すべてを初期化する必要があります。

関連する問題