【发布时间】:2014-01-09 23:53:30
【问题描述】:
我能够在 iOS 7 的表格部分中显示标题,但在 iOS 6 中没有显示文本。我知道您可以使用标题或自定义标题视图,但不能同时使用两者,所以我做了一定不要定义tableView:viewForHeaderInSection:。
这是相关代码。这是 UIViewController 的子类,而不是 UITableViewController。我需要一个粘性表格标题,所以我必须对表格视图进行自定义组合。
- (void)loadView
{
[super loadView];
// "width" and "height" properties are convenience methods
// that I defined in a UIView category.
self.tableView = [[UITableView alloc]
initWithFrame:CGRectMake(
0.0,
SEARCH_BAR_HEIGHT + self.avatarCollectionView.height,
self.view.width,
self.view.height - (SEARCH_BAR_HEIGHT + self.avatarCollectionView.height)
)
style:UITableViewStylePlain
];
[self.view addSubview:self.tableView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// displayAlphabet is an NSMutableArray of one character strings.
// It is a subset of the entire alphabet. For example, it can be:
// @[@"A", @"B", @"C", @"E", @"X", @"Z"]
return self.displayAlphabet.count;
}
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [self.displayAlphabet objectAtIndex:section];
}
- (NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.displayAlphabet;
}
如何让标题文本出现在 iOS 6 中?
【问题讨论】:
-
self.displayAlphabet 的 items 数据类型是什么?
-
您是否确保为
tableView:heightForHeaderInSection:返回一个非零高度,或者在表格视图上设置sectionHeaderHeight属性? -
无论是本地存储还是从 db/some where 获取,如何获取字母顺序
-
@Ramshad NSMutableArray
-
写入 NSLog(@"");在您的表委托中,并确保按预期返回值。
标签: ios iphone objective-c cocoa-touch uitableview