问题描述
我有一个关于在表格视图部分的页眉和页脚中打印文本的问题.我想在每一行的页脚中显示一些文本,但我在这样做时遇到了问题.当我开始下一部分时,它会从第一部分的下方开始绘制.要了解我到底需要什么,请转到设置"->常规"->网络"
I've a question about printing text in header and footer of table view section. I want to show some text in footer of each row, but I'm having problem doing so. When I start next section it start drawing from below of first one. To Get the idea what exactly I need, go to Settings->General->Network
在这个屏幕中,我们有多个部分,在前两个部分之后,我们有页脚信息.
In this screen, we've multiple sections and after first two sections we've footer information.
请在 iPhone 3G 上查看.(我不确定此屏幕是否适用于 iPhone 的其他变体.)
Please check this on iPhone 3G. (I'm not sure if this screen is avaiable on other variants of iPhone.)
如果您需要在说明中进行任何说明,请告诉我.
Let me know if you need any clarification in the description.
这里有两个函数实现,但没有按预期显示
Here are two functions implementation but it does not display as desired
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 1)
{
CGRect rect = CGRectMake(10.0f,40.0f,300.0f,250.0f);
UILabel* label = [[[UILabel alloc] initWithFrame:rect] autorelease];
label.backgroundColor = [UIColor clearColor];
label.text = NSLocalizedString(@"MessageHeader","");;
label.baselineAdjustment= UIBaselineAdjustmentAlignCenters;
label.lineBreakMode = UILineBreakModeWordWrap;
label.textAlignment = UITextAlignmentCenter;
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.font = [UIFont systemFontOfSize:14];
label.textColor = [UIColor darkGrayColor];
label.numberOfLines = 0;
UIView *view = [[[UIView alloc] initWithFrame:rect] autorelease];
[view addSubview:label];
return view;
}
}
return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (section == 1)
{
CGRect rect = CGRectMake(10.0f,80.0f,300.0f,250.0f);
UILabel* label = [[[UILabel alloc] initWithFrame:rect] autorelease];
label.backgroundColor = [UIColor clearColor];
label.text = NSLocalizedString(@"MessageFooter","");
label.baselineAdjustment= UIBaselineAdjustmentAlignCenters;
label.lineBreakMode = UILineBreakModeWordWrap;
label.textAlignment = UITextAlignmentCenter;
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.font = [UIFont systemFontOfSize:14];
label.textColor = [UIColor darkGrayColor];
label.numberOfLines = 0;
UIView *view = [[[UIView alloc] initWithFrame:rect] autorelease];
[view addSubview:label];
return view;
}
}
return nil;
}
这里有什么问题?为什么标题 &页脚文本一直到所有部分的底部.
What's wrong here? Why Header & footer text goes all the way to bottom of all the sections.
推荐答案
UITableViewDelegate 协议 允许您返回部分页眉和页脚的视图.只需实现此方法并返回一个 UILabel 填充您要显示的文本.
The UITableViewDelegate protocol allows you to return views for the header and footer of a section. Simply implement this method and return a UILabel filled with the text you want to display.
这篇关于标题中的文本 &表格部分 iPhone 的页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!