2016-01-20 114 views
0

這裏我提到了我寫的代碼,在滾動時UITableViewHeaderFooterView和第二次調用文本的方法是重疊的(多少次滾動文本添加多少時間),在這裏我提到屏幕截圖: http://prntscr.com/9sgq7xUITableViewHeaderFooterView中的文本重疊

_imgViewUser.imageURL = [NSURL URLWithString:modelData.user_image_big]; 
    _lblUserName.text  = modelData.posted_by; 
    _lblTime.text   = modelData.posted_time; 

    if ([modelData.commentArray count]) 
    { 
     _imgViewUser.imageURL = [NSURL URLWithString:[[modelData.commentArray objectAtIndex:0] valueForKey:@"cmt_user_small"]]; 
     NSString *nameStr = @""; 
     if ([GETVALUE(kUSERID) isEqualToString:[[modelData.commentArray objectAtIndex:0] valueForKey:@"cmt_userid"]]) { 
      nameStr = @"You"; 
     }else { 
      nameStr = [[modelData.commentArray objectAtIndex:0] valueForKey:@"full_name"]; 
     } 
     _lblUserName.text  = nameStr; 
     _lblTime.text   = [[modelData.commentArray objectAtIndex:0] valueForKey:@"cmt_post_time"]; 
    } 


    NSString *OriginalFrontendText = [[modelData.commentArray objectAtIndex:0] valueForKey:@"cmt_text"]; 
    UIFont *font      = [UIFont fontWithName:@"Arial" size:13.0]; 
    CGFloat descriptionHeight   = [OriginalFrontendText boundingRectWithSize:CGSizeMake(180, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font} context:nil].size.height; 

    [[self viewWithTag:tag]removeFromSuperview]; 

    STTweetUserName *commentLbl; 
    if ([modelData.comments_count intValue] > 1) { 
     commentLbl = [[STTweetUserName alloc]initWithFrame:CGRectMake(0, 39, self.frame.size.width-10, descriptionHeight) withFont:9.0 attributeTextColor:[UIColor darkGrayColor] name:@"See More"]; 
     commentLbl.text = [NSString stringWithFormat:@"%@See More",[[modelData.commentArray objectAtIndex:0] valueForKey:@"cmt_text"]]; 
    }else 
    { 
     commentLbl = [[STTweetUserName alloc]initWithFrame:CGRectMake(0, 39, self.frame.size.width-10, descriptionHeight) withFont:9.0 attributeTextColor:[UIColor darkGrayColor] name:nil]; 
     commentLbl.text    = [[modelData.commentArray objectAtIndex:0] valueForKey:@"cmt_text"]; 
    } 
    commentLbl.tag = tag; 

    if (commentLbl.tag == tag) { 
     [commentLbl removeFromSuperview]; 
    } 
    [self addSubview:commentLbl]; 

    commentLbl.detectionBlock = ^(STTweetHotUserName hotWord, NSString *string, NSString *protocol, NSRange range){ 
     showAlert(string, nil, @"OK", nil); 
     //[self SeeMoreClicked]; 
    }; 
    self.frame = CGRectMake(self.contentView.frame.origin.x, self.contentView.frame.origin.y, self.contentView.frame.size.width, 150); 

i am getting overlopping while scrolling 
+0

凡你在頁腳視圖設置表NSString文本

獲取寬度是多少?它在viewWillAppear方法的某個地方? –

+0

不,側面 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)部分 –

+0

你只是想在頁腳視圖中設置一些標籤。不是嗎? –

回答

0

使用下面的代碼,使您的頁腳視圖,但是你想

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 

    UIView * v = [[UIView alloc] init]; 
    v.frame = CGRectMake(0, 0, tableView.frame.size.width, 44); 

    UILabel * label = [[UILabel alloc] init]; 
    label.frame = CGRectMake(20, 0, tableView.frame.size.width/2, 44); 
    label.text = @"Some text"; 
    [v addSubview:label]; 

    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
    btn.frame = CGRectMake(label.frame.size.width+label.frame.origin.x, 0, tableView.frame.size.width/2, 44); 
    [btn addTarget:self action:@selector(seeMore) forControlEvents:UIControlEventTouchUpInside]; 
    btn.titleLabel.text = @"See more"; 
    [v addSubview:btn]; 

    return v; 
} 

自定義上面的代碼。這不會讓您的頁腳視圖與文字重疊。使用

- (CGSize)getHeightForText:(NSString *)text havingWidth:(CGFloat)widthValue andFont:(UIFont *)font { 
CGSize size = CGSizeZero; 
if (text) { 
    CGRect frame = [text boundingRectWithSize:CGSizeMake(widthValue, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName:font } context:nil]; 
    size = CGSizeMake(frame.size.width, frame.size.height+20.0f); 
} 
return size; 
} 
+0

對不起,先生Bharath,我沒有得到確切的結果。我試過我們的代碼。 我期待從那裏完成的文本按鈕想要啓動請參閱:http://prntscr.com/9shbta –

+0

Didi您解決了與上述代碼重疊的問題嗎? –

+0

該代碼不重疊。但我無法設置,但確切地說fram –