Ios UITableViewHeaderFooterView中的重叠文本

Ios UITableViewHeaderFooterView中的重叠文本,ios,objective-c,xcode6,xcode7,Ios,Objective C,Xcode6,Xcode7,在这里,我提到了我在UITableViewHeaderFooterView中编写的代码,在滚动时,该方法调用文本的第二次是重叠的(滚动多少次,文本添加多少次),这里我提到了屏幕截图: 使用以下代码创建页脚视图 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView * v = [[UIView alloc] init]; v.frame = C

在这里,我提到了我在UITableViewHeaderFooterView中编写的代码,在滚动时,该方法调用文本的第二次是重叠的(滚动多少次,文本添加多少次),这里我提到了屏幕截图:


使用以下代码创建页脚视图

- (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;
}
根据需要自定义上述代码。这不会让页脚视图与文本重叠

使用获取
NSString
文本的宽度

- (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;
}

在何处设置表的页脚视图?是否在VIEWWILLEXPEND方法中的某个位置?否,在侧边-(UIView*)表格视图:(UITableView*)表格视图FORFOOTERINSTITION:(NSInteger)部分您只需在页脚视图中设置一个带有一些文本的标签。是吗?是的文本,但文本结尾我想添加选项,如“看得更多”,即“看得更多”,它将触手可及对不起,巴拉斯先生,我没有得到确切的结果。我试过你的密码。我所期望的是从那里开始的文本完成按钮,请参考:您是否用上述代码解决了重叠问题?该代码没有重叠。但我无法设置,但fram exactlyCan您可以发送一些屏幕截图,它看起来如何添加上述代码?所以这里的问题,你们只有按钮的位置。不是吗?如果是这种情况,请使用btn.frame“x”值播放。那会对你有帮助的。还可以看到我的更新答案,我添加了一个新方法来查找字符串文本的CGSize。使用此方法计算页脚视图中标签的宽度。
- (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;
}