我有tableView,我从数组中获取数据,也从数组中获取节和节标题的数量,但是当我从数组中提供节标题时,它会破坏App。
获取数组中的值:
NSArray *tempArray =[[DataController staticVersion] startParsing:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/getCategory.php"];
for (int i = 0; i<[tempArray count]; i++) {
id *item = [tempArray objectAtIndex:i];
NSDictionary *dict = (NSDictionary *) item;
ObjectData *theObject =[[ObjectData alloc] init];
[theObject setCategoryID:[dict objectForKey:@"CategoryID"]];
[theObject setCategoryTitle:[dict objectForKey:@"CategoryTitle"]];
[theObject setCategoryDescription:[dict objectForKey:@"CategoryDescription"]];
[theObject setCategoryAddedByUserID:[dict objectForKey:@"CategoryAddedByUserID"]];
[theObject setCategoryAddedDateTime:[dict objectForKey:@"CategoryAddedDateTime"]];
[categoryArray addObject:theObject];
[theObject release];
theObject=nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [categoryArray count] ;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
[categoryArray objectAtIndex:section];
}
答案 0 :(得分:0)
您正在ObjectData
中添加categoryArray
类的实例。 tableView:titleForHeaderInSection:
方法要求NSString
对象将其设置为节的标题。使用titleForHeaderInSection:
方法检查您要返回的内容。它必须是NSString
对象。如果要将类别标题设置为节标题标题,请将categoryTitle返回为
return [(ObjectData*)[categoryArray objectAtIndex:section] categoryTitle];
答案 1 :(得分:0)
尝试这样,
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection(NSInteger)section
{
return [[categoryArray objectAtIndex:section] valueForKey:@"title"];//replace title with your key value
}
答案 2 :(得分:0)
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
期待一个字符串作为回报。
尝试
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
ObjectData *theObject =[categoryArray objectAtIndex:section];
return theObject.categoryTitle;
}