0

我有tableView,我从数组中获取数据,也从数组中获取部分和部分标题的数量,但是当我从数组中给出部分标题时,它会破坏应用程序。

获取数组中的值:

   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];

  }
4

3 回答 3

0

您正在将类的实例添加ObjectDatacategoryArray. 该tableView:titleForHeaderInSection:方法要求一个NSString对象将其设置为节的标题。检查您在titleForHeaderInSection:方法中返回的内容。它必须是一个NSString对象。如果要将类别标题设置为节标题,请将 categoryTitle 返回为

return [(ObjectData*)[categoryArray objectAtIndex:section] categoryTitle];
于 2013-06-10T06:21:19.953 回答
0

试试这样

 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection(NSInteger)section
     {
       return [[categoryArray objectAtIndex:section] valueForKey:@"title"];//replace title with your key value
     }
于 2013-06-10T06:23:04.373 回答
0
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

期望一个字符串作为回报。

尝试

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    ObjectData *theObject =[categoryArray objectAtIndex:section];
    return theObject.categoryTitle;
}
于 2013-06-10T06:44:20.290 回答