- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题是这两个部分有时是空的,所以我不知道当它们变空时如何防止崩溃。 self.globalSections 是一个全局 NSMutableArrays,由本地两个 NSMutableArrays 存储,这两个 NSMutableArrays 是我的 UITableView 的第一部分和第二部分。
这是我的代码:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (mySearchBar.text.length > 0)
{
if(section == 0)
{
//below are if statements I have tried, but not working...
//NSUInteger globalSectionsOne = [self.globalSections indexOfObject:[self.globalSections objectAtIndex:0]];
//if ([[self.globalSections objectAtIndex:0]count] >=1)
// if (globalSectionsOne!=NSNotFound)
//if (globalSectionsOne >= 1)
//{
NSLog(@"sections counts");
NSUInteger firstSectionCount = [[self.globalSections objectAtIndex:0]count];
NSString *firstSectionString = [NSString stringWithFormat:@"%i Exact match(es)", firstSectionCount];
return firstSectionString;
//}
//else {return @"";}
}
else if (section == 1)
{
//another same code, except the objectAtIndex is at 1 instead of 0.
请指出正确的方向,谢谢。
编辑:
我在这个方法中做了修改:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (mySearchBar.text.length > 0 && [self.globalSections count] == 2)
{
return 2;
}
else
{
return 1;
}
//return 1;
}
这样可以吗?
最佳答案
您可以这样避免在 titleForHeaderInSection:
中重复代码:
if (mySearchBar.text.length > 0)
{
if ([self.globalSections count] > section)
{
int sectionCount = [[self.globalSections objectAtIndex:section] count];
NSString *matchWord = (sectionCount == 1) ? @"match" : @"matches";
return [NSString stringWithFormat:@"%i Exact %@", sectionCount, matchWord];
}
else
{
return @"";
}
}
关于iOS titleForHeaderInSection 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8733527/
我的应用程序在4.3.1模拟器中显示此内容,在5.0模拟器中显示此内容。 这是代码: - (NSString *)tableView:(UITableView *)tableView titleFor
我有一个 UITableviewController ,其标题 View 类似于: https://github.com/andersonkxiass/UITableViewHeader 但是我的表格
我像这样从 plist 加载数据到 uitableview: - (void)viewDidLoad { [super viewDidLoad]; NSArray *documentP
问题是这两个部分有时是空的,所以我不知道当它们变空时如何防止崩溃。 self.globalSections 是一个全局 NSMutableArrays,由本地两个 NSMutableArrays 存储
此应用仅供研究和学习之用。我是开发新手,所以这没什么特别的,真的。 它应该显示一个包含一些联系人的 TableView,这些联系人分为两个不同的类别:最近和 friend 但是,当我尝试使用 Titl
这是我添加的。它只是列出了每个字母字符下的所有 objectsForCharacters。 - (void)tableViewDidLoadModel:(UITableView*)tableView
所以我的问题是我的部分上方的文字太长而被截断。 有什么方法可以解决这个问题,比如让它长两行? 感谢任何帮助 最佳答案 您需要定义heightForHeaderInSection 并自定义viewFor
就调用命名我的 header 而言,我似乎无法做到正确。 如果您想知道我的模型是关于什么的 - 它基本上是一本包含美丽地点的字典,按字母顺序书写。 有人可以帮助我吗,因为我真的无法弄清楚我做错了什么?
我有一个简单的项目,它有一个 View ,这个 View 里面只包含一个 TableView 。表格 View 被分组并且有一个简单的原型(prototype)单元格。 我已经实现了 titleFor
我有如下程序:..- 但是,我想在 TitleForHeaderInSection 中按日期降序排列数据,并且还想将标题中的日期格式化为 NSDateFormatter *formatter = [[
我将一个 TableView 添加到 View Controller ,然后尝试在 IOS 6.0 中更改其节标题。 每次调用特定函数时我都会更改 header 字符串,所以我不想处理 (UIView
我有一些非常简单的代码来返回节标题的标题: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSIn
在长时间阅读和检查代码之后,我为拥有一个包含部分和部分标题的自定义表格 View 而感到自豪,所有这些都是从核心数据对象中填充的。现在我需要自定义部分标题和背景颜色。我已经看到它完成了,但是在 vie
在我的核心数据应用程序中,我使用 FetchedResultsController。通常要在 UITableView 中设置标题的标题,您将实现以下方法,如下所示: - (NSString *)tab
尝试在 tableView 的 titleForHeaderIn 部分返回复合字符串时遇到一个奇怪的问题。 如果我 NSLog 字符串,它似乎很好,但是当我返回它时,它崩溃了! 这是我的代码: - (
我用下面的代码在group tableview title header上设置标题,但是默认文本是AlignmentLeft,如何AlignmentCenter? - (NSString *)tabl
我正在使用 titleForHeaderInSection 来显示 UITableView 部分的标题。它适用于 iOS6 SDK,但 iOS7 SDK 以所有大写字母显示标题。 我猜这是 Apple
我正在尝试从 Controller 构建一个 tableView,而不仅仅是在 Storyboard中自己构建静态单元格。我的所有单元格都是从一个数组填充的,并且我希望节标题从不同的数组中显示。 nu
我有一个计算卡路里的应用程序。用户输入他们的卡路里(每一点食物都成为 TableView 中的一行。每个部分代表一天。 我有一个部分标题,添加了当天的所有卡路里。 现在我有一年的输入,加载应用程序的性
我正在使用 MRC(不要使用 ARC) 节.h @property (nonatomic, assign) NSString* headerTitle; section.m - (instancety
我是一名优秀的程序员,十分优秀!