2017-12-16 9 views
0

私はDynamic TableView、Textfield、およびButtonsを実装しました。私の問題は、UITableViewCellの最初の行のボタンを隠すと、他の5行のセルボタンも非表示になります。Objective CのDynamic UITableViewCellで特定の行ボタンを非表示にする方法は?

この問題の解決策を提案する人はいますか?

私は

ladiesdetails=[[NSMutableArray alloc]initWithObjects:@"2",@"0",@"0",@"0",@"0",@"0", nil]; 



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return 6; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 


    static NSString *CellIdentifier = @"cell1"; 

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[passengerdetailcell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
if([[ladiesdetails objectAtIndex:indexPath.row] intValue]==2) 
{ 
cell.malebutton.hidden=yes; 
} 
return cell; 
} 
+0

'indexPath.row == 2'でオスのボタンを隠すと、他のindexpathも表示する必要があります。 elseの中に 'hidden = no;'を書いて、if条件の一部として試してみてください。 –

答えて

1

セルの再利用のため、あなたが1以下のようにセルを割り当てる使用しているためそれは起こります。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     // Return the number of rows in the section. 
     return 6; 
    } 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     PassengerDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PassengerDetailCell" forIndexPath:indexPath]; 
     if([[self.ladiesdetails objectAtIndex:indexPath.row] intValue]==2) 
     { 
      cell.maleButton.hidden = TRUE; 
     } 
     return cell; 
    } 
+3

簡潔さは受け入れられますが、より完全な説明が良いです。 –

+1

あなたの貢献に感謝しています。 –

1

ちょうど他の条件を入れて、cellForRowAtIndexPathメソッドでボタンを表示させる。..コードの下にしようとしています。他の条件があればそれを追加してください。この

bool flag = ([[ladiesdetails objectAtIndex:indexPath.row] intValue] == 2) 
cell.malebutton.hidden = flag 
+0

このコードも私のために働いています、ありがとうたくさん.. –

0

よう

if([[ladiesdetails objectAtIndex:indexPath.row] intValue]==2) { 
    cell.malebutton.hidden = YES; 
} else { 
    cell.malebutton.hidden = NO; 
} 
+0

PassengerDetailTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@ "PassengerDetailCell" forIndexPath:indexPath]; この行は、NSInternalConsistencyyExceptionのようなエラーを表示します。セルをデキューできません。このエラー –

+0

正しいヘッダーとクラス名が同じかどうかをチェックします。私のコードは異なるクラス名を持ちます – Vinodh

関連する問題