Ios 如何从iPhone中的任何数组对象设置表节标题。
我有tableView,我从数组中获取数据,也从数组中获取节数和节标题,但当我从数组中给出节标题时,它会破坏应用程序 获取数组中的值:Ios 如何从iPhone中的任何数组对象设置表节标题。,ios,iphone,ipad,uitableview,Ios,Iphone,Ipad,Uitableview,我有tableView,我从数组中获取数据,也从数组中获取节数和节标题,但当我从数组中给出节标题时,它会破坏应用程序 获取数组中的值: NSArray *tempArray =[[DataController staticVersion] startParsing:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/getCategory.php"]; for (int i = 0; i<[tempArray cou
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];
}
NSArray*tempArray=[[DataController staticVersion]startParsing:@”http://www.celeritas-solutions.com/pah_brd_v1/productivo/getCategory.php"];
对于(int i=0;i您正在将ObjectData
类的实例添加到categoryArray
中。tableView:titleForHeaderInSection:
方法要求一个NSString
对象将其设置为节头。检查titleForHeaderInSection:
方法中返回的内容。它必须是NSString
对象。如果要将类别标题设置为节标题,请将categoryTitle返回为
return [(ObjectData*)[categoryArray objectAtIndex:section] categoryTitle];
试着这样,
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection(NSInteger)section
{
return [[categoryArray objectAtIndex:section] valueForKey:@"title"];//replace title with your key value
}
期望得到一个字符串作为回报
试一试
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
ObjectData *theObject =[categoryArray objectAtIndex:section];
return theObject.categoryTitle;
}