2017-11-17 7 views
0

私はこの問題を1日以来回避していますが、この問題を解決するには多くの方法を試しましたが、まだ成功していません。 3つのカスタムセルを持つテーブルビューがあり、最後の2つのセクションのセクションヘッダーが追加されています。ここにスクリーンショットがあります。 Header Gender is repeatingUITableViewのサイズがUITableViewのセルで増加すると、セクションヘッダーが繰り返されます

TextViewにテキストを入力すると、最後のセクションのヘッダーが表示されます。 My TextViewは編集可能で、テキストサイズごとにテキストビューのサイズを調整するためにスクロールを無効にしました。

ここにコードがあります。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 3; 
    } 

    -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
    { 
     NSArray *titleArray = @[@"",@"About You",@"Gender"]; 

     NSString *titleHeading = [titleArray objectAtIndex:section]; 

     return titleHeading; 
    } 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
    return section == 0 ? CGFLOAT_MIN : 35; 
} 

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

     NSString *identifier = [NSString stringWithFormat:@"cell%ld,%ld",indexPath.section, indexPath.row]; 
     id cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 

if (indexPath.section == 1) 
      { 
       ProfileAboutCell *cellObj = [tableView dequeueReusableCellWithIdentifier:identifier]; 
       if (!cellObj) 
       { 
        [_tableView registerNib:[UINib nibWithNibName:@"ProfileAboutCell" bundle:nil] forCellReuseIdentifier:identifier]; 
        cellObj = [tableView dequeueReusableCellWithIdentifier:identifier]; 
       } 
       cellObj.selectionStyle = UITableViewCellSelectionStyleNone; 

       //[cellObj.txtAboutYou layoutIfNeeded]; 
     cellObj.txtAboutYou.delegate = self; 
     cellObj.lbl = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 0.0,cellObj.txtAboutYou.frame.size.width - 10.0, 34.0)]; 
     cellObj.lbl.text = @"About You"; 
     [cellObj.lbl setBackgroundColor:[UIColor clearColor]]; 
     [cellObj.lbl setTextColor:[UIColor lightGrayColor]]; 
     [cellObj.txtAboutYou addSubview:cellObj.lbl]; 
    //  [cellObj.txtAboutYou setText:[kUserDefaults valueForKey:kAbout]]; 
     //[cellObj.txtAboutYou sizeToFit]; 



       cell = cellObj; 
      } 

     return cell; 
     } 

TextView委任方法。

-(void)textViewDidChange:(UITextView *)textView 
{ 
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1]; 
    ProfileAboutCell *cell = [_tableView cellForRowAtIndexPath:indexPath]; 

    if(![textView hasText]) { 
     cell.lbl.hidden = NO; 
    } 
    else{ 
     cell.lbl.hidden = YES; 
    } 
    NSInteger len = textView.text.length; 
    cell.lblChar.text=[NSString stringWithFormat:@"%li",500-len]; 

    [_tableView beginUpdates]; 
    [_tableView endUpdates]; 
} 

私はこれを試しましたが、#solutionですが、ヘルプはありません。どんな援助もこの方向で高く評価されるだろう。前もって感謝します。

+0

上記の行のテキストビューが縮小または拡大されている間にヘッダーが繰り返されます。 – Hrshil

答えて

0

問題の私の理解から、各セクションの "cellForRowAtIndexPath"に設定したのと同じ方法で、 "titleForHeaderInSection"のセクションヘッダーを設定することで解決できます。 ヘッダーを設定しないセクション問題は発生しません。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    NSArray *titleArray = @[@"",@"About You",@"Gender"]; 



if (indexPath.section == 1) { 
     NSString *titleHeading = [titleArray objectAtIndex:1]; 
     return titleHeading; 
} 
if (indexPath.section == 2) { 
     NSString *titleHeading = [titleArray objectAtIndex:2]; 

     return titleHeading; 
} 

    } 
+0

いいえ...これは、すべてのセクションで同じタイトルヘッダー「あなたについて」を繰り返しています。 – Hrshil

+0

このコードの出力を参照してください。 https://ibb.co/b1sqSm – Hrshil

関連する問題