我有一个简单的问题,是否有人能够在CollectionView中成功创建和实现节标题,类似于TableView中的标题?我做了很多研究,发现了代码片段,但没有成功实现这一目标的人的真实例子.我有一个照片的CollectionView,我想要实现的是根据他们拍摄的月份将它们分组.我已经设法将它们分成了这些部分,但我现在所有的部分都是每个部分开头的空白标题.我想要做的是显示当前空白标题中的月份.同样,每个部分的字母都显示在显示联系人的Tableview中.感谢您的回复.
我正在尝试制作一个包含多个部分的表(如联系人应用程序)一切顺利,我在每个部分的顶部创建了自定义部分标题,显示代表此部分的字符.问题是我希望它像是联系人确切地说标题保持在顶部直到下一个标题崩溃...它怎么会发生这种情况
我正在使用以下代码(以便您更容易理解
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [stateIndex count];
}
- (UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section
{
UILabel *sectionHeader = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
sectionHeader.backgroundColor = [UIColor clearColor];
sectionHeader.font = [UIFont boldSystemFontOfSize:18];
sectionHeader.textColor = [UIColor whiteColor];
sectionHeader.text = [stateIndex objectAtIndex:section];
sectionHeader.textAlignment=UITextAlignmentCenter;
return sectionHeader;
}
//---set the index for the table---
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return stateIndex;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//---get the letter in each section; e.g., A, B, C, …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的简单问题(我希望如此).如何将UITableview中的节标题颜色从默认蓝色更改为黑色透明?提前致谢.
得到了一个默认的分组样式表,如下面的左侧屏幕截图,但它看起来有不同的节标题高度,顶部首先是69 px测量,而其余的是40 px.
为什么?它们应该是相同的高度,不是吗?
所以我想用它的方法制作它们tableView:heightForHeaderInSection:,return 40
但是.....看起来更糟糕!即使将章节标题放在......如右下图所示,它也会放大高于中间的高度.

我只想拥有相同高度的节头.如何使它工作?
我已经更改了tableviews部分的backgroundColor/backgroundImage.
我使用普通的tableView.不用担心,使用此代码可以正常工作:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 728, 40)] autorelease];
sectionView.backgroundColor = [UIColor greenColor];
//For using an image use this:
//sectionView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"whiteBackground.png"]];
return sectionView;
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是,章节标题已经消失.
我正在使用以下代码设置该部分的标题:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
return @"";
} else {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo name];
}
}
Run Code Online (Sandbox Code Playgroud)
如果我不使用,我会得到章节标题
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
需要你的帮助.
非常感谢.
编辑1:
感谢Mutix:
就我而言,答案是:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { …Run Code Online (Sandbox Code Playgroud) 由于导航栏样式是半透明的,我将第一部分标题(部分#0)隐藏在我的导航栏下.
我知道之前已经问过这个问题,并且要解决这个问题:
self.navController.navigationBar.translucent = YES;
Run Code Online (Sandbox Code Playgroud)
这会使问题视图正确 - 部分标题出现在导航栏下方而不是隐藏在它后面,这就是我想要的.
但是,这会使我的其他视图设计无效,并在我的导航栏下方留下所有空间中的额外空格.
如何在正确的位置获取节标题?
我无法设置自定义UITableView节标题的动画.
目标是创建可折叠部分.
当我第一次按照预期动画时点击自定义标题,然而每次之后它会在原始位置留下副本并为另一个创建动画.
图片示例:
替代文字http://img35.imageshack.us/img35/4018/screenshot2010022722565.png
替代文字http://img291.imageshack.us/img291/8287/screenshot2010022723035.png
我的自定义标题:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView* customView = [[[UIView alloc]initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)]autorelease];
customView.backgroundColor = [UIColor lightGrayColor];
UILabel * headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor darkGrayColor];
headerLabel.font = [UIFont boldSystemFontOfSize:16];
headerLabel.frame = CGRectMake(10, 7, 260.0, 44.0);
headerLabel.textAlignment = UITextAlignmentCenter;
NSDictionary *dictionary = [self.data objectAtIndex:section];
headerLabel.text = [dictionary objectForKey:@"Title"];
[customView addSubview:headerLabel];
// add button to right corner of section
UIButton* headerButton = …Run Code Online (Sandbox Code Playgroud) 在默认联系人应用程序的Android 4.0中,列表视图包含标题部分.当前可见部分的标题保留在ListView的顶部,直到下一个新部分变为可见并关闭旧标题.
我看到有几个gitHub项目(https://github.com/emilsjolander/StickyListHeaders)可用于集成它,但是有任何默认组件或Android支持库组件中的任何一个,我们可以用它来实现这个实现?

在以下代码中:
NSFetchedResultsController *frc =
[[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:myManagedObjectContext
sectionNameKeyPath:@"store"
cacheName:@"SomeCache"
];
Run Code Online (Sandbox Code Playgroud)
sectionNameKeyPath的@"store"值实际上指向一个Store实体的关系,该实体具有我真正需要的name属性作为我的节标题标题.
但是我的代码设置方式无法完成,因为我改为获取部分标题,如:0x5b504f0 0x5b51190这是我所知道的Store对象的代码数据地址.
我如何使用NSFetchedResultsController以便我可以告诉它我希望它从sectionNameKeyPath获取其名称属性:@"store"?或者还有其他一些解决方法吗?
我有一个UITableView带有两个部分和动态行数的普通表格视图。我还UIView为节标题返回 a 。
一切正常,除非桌子重新加载。节标题位置移动到随机位置,直到视图开始滚动。
标题视图和超级视图中的自动布局似乎没有违反。我已经设置了表格页脚视图nil或显示分页动画。并且表格视图在滚动视图中。
任何建议或解决方案为什么会出现节标题出现此故障。而这个故障只发生在 iOS 9
sectionheader ×10
uitableview ×7
ios ×4
iphone ×3
objective-c ×2
android ×1
animation ×1
height ×1
ios9 ×1
listview ×1
title ×1
translucency ×1