2016-03-29 2 views
0

は私のカスタムであるTableViewCellを持っています。各行に2つのボタンがあります。一つは表示されているボタンをタップすると、私はこれをカバーしました、私の問題は、私が下にスクロールすると、Reuseidentifierのために他の隠れたボタンが表示されます。TableViewCellでUIButtonを有効にすると、より多くのセルが表示されます

私が選択した行からボタンを表示するにはどうすればよいですか?

希望しない場合は私には分かります。

ありがとうございます。

+1

セルの 'prepareForReuse'メソッドのボタンを無効にします。 – EmilioPelaez

答えて

1

あなたがのtableView残りのボタンをスクロール隠されています。あなたが選択したインデックスが何であれ、それをMutableArrayに追加してください。cellForRowAtIndexPathその配列にindexPathが含まれている場合は、条件を1つ入れてください。

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

    CutomTableView *cell=[tableView dequeueReusableCellWithIdentifier:@"CellId" forIndexPath:indexPath]; 
    [cell.show setTag:indexPath.row]; 
    [cell.show addTarget:self action:@selector(showButtonACtion:) forControlEvents:UIControlEventTouchUpInside]; 
NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0]; 
//self.selectedRow is NSMutable Array 
    if ([self.selectedRow containsObject:selectedIndexPath]) { 
     [cell.hideBtn setHidden:NO]; 
    }else{ 
     [cell.hideBtn setHidden:YES]; 
    } 
    return cell; 
} 
-(void)showButtonACtion:(UIButton*)sender{ 
    NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0]; 
    [self.selectedRow addObject:myIP]; 
    [self.tableV reloadData]; 
    } 
+0

Rubiyaに感謝します。私はあなたにどのように終わりをさせるでしょう。 –

+0

Rubiyaさん、ありがとうございました! –

0

特定のボタンをクリックして別のボタンを表示すると、そのNSIndexpathを保存するだけです。例えば

、 あなたは

[mutableDict setValue:@"YES" forKey:[NSString stringWithFormat:@"%@", indexPath.row]]; 

としてNSMutableDicionaryに値を追加し、cellForRowAtIndexPathメソッドでは、特定のindexPathをチェックし、その後、第二行をクリックしている場合。

特定の行に対して@ "YES"が見つかるたびに、ボタンを表示または非表示にするロジックを実装します。

希望すると、これが役立ちます。あなたはその1 NSMutableArrayのを取ると、それにメモリを割り当てる任意の条件を入れずcellForRowAtIndexPathにsetHidden方法を書いたので、

+0

Dhruvikありがとうございましたが、このボタンはTableViewCell.mで処理されます。ここでキャッチされたアクションを意味します。cellViewRowAtIndexPathメソッドでTableViewCellで処理されたNSMutableDictionary情報をTableViewCellで処理する方法を教えてください。 –

+0

これを実現するためにデリゲートを実装することができます。 @トニー。 – Dhruvik

0
-(IBAction)firstButton:(UIControl *)sender 
{ 
     UIButton *button = (UIButton*)sender; 
     NSIndexPath *myIP = [NSIndexPath indexPathForRow:sender.tag inSection:0]; 

     CustomCell *cell = (CustomCell*)[self.tableView cellForRowAtIndexPath:myIP]; 
     [cell.button2 setHidden:NO];. 
} 
関連する問題