2016-04-26 10 views
1

私はテーブルビューを持っています。以下は私のcellForRowAtIndexPathコードですuitableviewから特定のビューを隠す

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

    UITableViewCell *cell = nil; 
    cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@""]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:nil]; 
     tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
    } 
    orderDetailsLabel = [[UILabel alloc]init]; 
    shipmentStatusLabel = [[UILabel alloc]init]; 
    ratingandFeedbackLabel = [[UILabel alloc]init]; 

    HCSStarRatingView *starRatingView; 

    UILabel *suggestionsLabel; 
    UILabel *checkBoxLabel1; 
    UIButton *checkBoxButton1; 
    UIButton *saveButton; 
    UIImageView *checkbox1; 
    UITextView *feedBackTextView; 

    suggestionsLabel = [[UILabel alloc]init]; 

    checkBoxLabel1 = [[UILabel alloc]init]; 


    checkBoxButton1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
    checkbox1 = [[UIImageView alloc]init]; 
    feedBackTextView = [[UITextView alloc]init]; 

    if (indexPath.row == 0) 
    { 

     ratingandFeedbackLabel.frame = CGRectMake(20, 5, 350, 20); 
     ratingandFeedbackLabel.text = [ratingandFeedbackArray objectAtIndex:indexPath.row]; 
     ratingandFeedbackLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14]; 

     starRatingView = [[HCSStarRatingView alloc] initWithFrame:CGRectMake(20, 15, 100, 50)]; 
     starRatingView.maximumValue = 5; 
     starRatingView.minimumValue = 0; 
     starRatingView.value = 0; 
     starRatingView.tintColor = [UIColor colorWithRed:254/255.0 green:174/255.0 blue:77/255.0 alpha:1]; 
     starRatingView.backgroundColor = [UIColor clearColor]; 
     [starRatingView addTarget:self action:@selector(didChangeValue:) forControlEvents:UIControlEventValueChanged]; 

    } 
    else if (indexPath.row == 1) 
    { 
     checkbox1.frame = CGRectMake(20, 0, 20, 20); 
     checkbox1.image = [UIImage imageNamed:@"[email protected]"]; 
     checkBoxButton1.frame = CGRectMake(20, 0, 20, 20); 
     [checkBoxButton1 addTarget:self action:@selector(checkBoxButton1Tapped:) forControlEvents:UIControlEventTouchUpInside]; 

     suggestionsLabel.frame = CGRectMake(10, 185, 300, 30); 
     suggestionsLabel.text = @"Your feedback will help us make better *"; 
     suggestionsLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13]; 

     CGRect screenRect = [[UIScreen mainScreen] bounds]; 

     if (screenRect.size.height == 480) 
     { 
      tableView.scrollEnabled = YES; 
      feedBackTextView.frame = CGRectMake(18, 220, 285, 100); 
      saveButton.frame = CGRectMake(120, 330, 70, 30); 

     } 

     UIColor *borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0]; 
     feedBackTextView.text = @""; 

     [saveButton setTitle:@"Save" forState:UIControlStateNormal]; 
     [saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
     [saveButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; 

    } 

    tableView.tableFooterView = [UIView new]; 

    [cell.contentView addSubview:orderDetailsLabel]; 
    [cell.contentView addSubview:shipmentStatusLabel]; 
    //[cell.contentView addSubview:starRatingImageView]; 
    [cell.contentView addSubview:ratingandFeedbackLabel]; 
    [cell.contentView addSubview:suggestionsLabel]; 

    [cell.contentView addSubview:checkBoxButton1]; 

    [cell.contentView addSubview:checkBoxLabel1]; 
    [cell.contentView addSubview:feedBackTextView]; 
    [cell.contentView addSubview:starRatingView]; 
    [cell.contentView addSubview:saveButton]; 

    return cell; 
} 

他のメソッドでは、receiveStarRatingData、私はユーザーからステータスコードを受け取っています。ステータスコードが1の場合、checkbox、suggestionsLabel、saveボタン、およびfeedBackTextViewを表示したくありません。どのように私はそれらを非表示にするか、またはreceiveStarRatingDataメソッドからそれらを削除できますか?

+0

にあなたのcontentviewにサブビューを追加し続けます。最終的にUIが遅くなり、時には応答しなくなる – Joshua

答えて

1

あなたはreceiveStarRatingData方法でデータを受け取るたらステータスコードが真:)に1セットこの変数である場合:) isStatusCodeOneのようなあなたのtableViewコントローラにブール変数を持っているなどcellForRowatIndexpathself.tableView.reloadData()ハンドルラベルを呼び出してのtableViewをリロードすることができます

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = nil; 
    cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@""]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:nil]; 
     tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
    } 
    orderDetailsLabel = [[UILabel alloc]init]; 
    shipmentStatusLabel = [[UILabel alloc]init]; 
    ratingandFeedbackLabel = [[UILabel alloc]init]; 

    HCSStarRatingView *starRatingView; 

    UILabel *suggestionsLabel; 
    UILabel *checkBoxLabel1; 
    UIButton *checkBoxButton1; 
    UIButton *saveButton; 
    UIImageView *checkbox1; 
    UITextView *feedBackTextView; 

    if (!self.isStatusCodeOne) { 
     suggestionsLabel = [[UILabel alloc]init]; 

     checkBoxLabel1 = [[UILabel alloc]init]; 


     checkBoxButton1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
     checkbox1 = [[UIImageView alloc]init]; 
     feedBackTextView = [[UITextView alloc]init]; 
    } 

    if (indexPath.row == 0) 
    { 

     ratingandFeedbackLabel.frame = CGRectMake(20, 5, 350, 20); 
     ratingandFeedbackLabel.text = [ratingandFeedbackArray objectAtIndex:indexPath.row]; 
     ratingandFeedbackLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14]; 

     starRatingView = [[HCSStarRatingView alloc] initWithFrame:CGRectMake(20, 15, 100, 50)]; 
     starRatingView.maximumValue = 5; 
     starRatingView.minimumValue = 0; 
     starRatingView.value = 0; 
     starRatingView.tintColor = [UIColor colorWithRed:254/255.0 green:174/255.0 blue:77/255.0 alpha:1]; 
     starRatingView.backgroundColor = [UIColor clearColor]; 
     [starRatingView addTarget:self action:@selector(didChangeValue:) forControlEvents:UIControlEventValueChanged]; 

    } 
    else if (indexPath.row == 1) 
    { 
     if(!isStatusCodeOne){ 
      checkbox1.frame = CGRectMake(20, 0, 20, 20); 
      checkbox1.image = [UIImage imageNamed:@"[email protected]"]; 
      checkBoxButton1.frame = CGRectMake(20, 0, 20, 20); 
      [checkBoxButton1 addTarget:self action:@selector(checkBoxButton1Tapped:) forControlEvents:UIControlEventTouchUpInside]; 

      suggestionsLabel.frame = CGRectMake(10, 185, 300, 30); 
      suggestionsLabel.text = @"Your feedback will help us make better *"; 
      suggestionsLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13]; 

     } 
     CGRect screenRect = [[UIScreen mainScreen] bounds]; 

     if (screenRect.size.height == 480) 
     { 
      tableView.scrollEnabled = YES; 
      feedBackTextView.frame = CGRectMake(18, 220, 285, 100); 
      saveButton.frame = CGRectMake(120, 330, 70, 30); 

     } 

     UIColor *borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0]; 
     feedBackTextView.text = @""; 

     [saveButton setTitle:@"Save" forState:UIControlStateNormal]; 
     [saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
     [saveButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; 

    } 


    } 
    tableView.tableFooterView = [UIView new]; 
    [cell.contentView addSubview:orderDetailsLabel]; 
    [cell.contentView addSubview:shipmentStatusLabel]; 
    //[cell.contentView addSubview:starRatingImageView]; 
    [cell.contentView addSubview:ratingandFeedbackLabel]; 
    if(!isStatusCodeOne){ 
     [cell.contentView addSubview:suggestionsLabel]; 

     [cell.contentView addSubview:checkBoxButton1]; 

     [cell.contentView addSubview:checkBoxLabel1]; 
     [cell.contentView addSubview:feedBackTextView]; 
     [cell.contentView addSubview:starRatingView]; 
     [cell.contentView addSubview:saveButton]; 
    } 
    return cell; 
} 

とisStatusCodeOneを設定した後receiveStarRatingDataメソッド呼び出しself.tableView.reloadData() :)

関連する問題