は私のカスタムであるTableViewCell
を持っています。各行に2つのボタンがあります。一つは表示されているボタンをタップすると、私はこれをカバーしました、私の問題は、私が下にスクロールすると、Reuseidentifierのために他の隠れたボタンが表示されます。TableViewCellでUIButtonを有効にすると、より多くのセルが表示されます
私が選択した行からボタンを表示するにはどうすればよいですか?
希望しない場合は私には分かります。
ありがとうございます。
は私のカスタムであるTableViewCell
を持っています。各行に2つのボタンがあります。一つは表示されているボタンをタップすると、私はこれをカバーしました、私の問題は、私が下にスクロールすると、Reuseidentifierのために他の隠れたボタンが表示されます。TableViewCellでUIButtonを有効にすると、より多くのセルが表示されます
私が選択した行からボタンを表示するにはどうすればよいですか?
希望しない場合は私には分かります。
ありがとうございます。
あなたがの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];
}
Rubiyaに感謝します。私はあなたにどのように終わりをさせるでしょう。 –
Rubiyaさん、ありがとうございました! –
特定のボタンをクリックして別のボタンを表示すると、そのNSIndexpathを保存するだけです。例えば
、 あなたは
[mutableDict setValue:@"YES" forKey:[NSString stringWithFormat:@"%@", indexPath.row]];
としてNSMutableDicionaryに値を追加し、cellForRowAtIndexPathメソッドでは、特定のindexPathをチェックし、その後、第二行をクリックしている場合。
特定の行に対して@ "YES"が見つかるたびに、ボタンを表示または非表示にするロジックを実装します。
希望すると、これが役立ちます。あなたはその1 NSMutableArrayのを取ると、それにメモリを割り当てる任意の条件を入れずcellForRowAtIndexPath
にsetHidden方法を書いたので、
Dhruvikありがとうございましたが、このボタンはTableViewCell.mで処理されます。ここでキャッチされたアクションを意味します。cellViewRowAtIndexPathメソッドでTableViewCellで処理されたNSMutableDictionary情報をTableViewCellで処理する方法を教えてください。 –
これを実現するためにデリゲートを実装することができます。 @トニー。 – Dhruvik
-(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];.
}
セルの 'prepareForReuse'メソッドのボタンを無効にします。 – EmilioPelaez