サーバー上に、tableView に表示したいデータがあります。
問題は、カテゴリに基づいてデータを表示したいので、セクションタイトルとなるカテゴリを持つ配列カテゴリがあり、その中にデータがあるため、セクションにデータを表示するには、配列を宣言する必要があることです。
たとえば、3 つのカテゴリがある場合、データを入力するために 3 つの配列を作成する必要がありますが、カテゴリが動的でサーバーから取得されるため、より多くのカテゴリがある場合はどうなりますか。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [categoryArray count] ;
}
そして、セクションのタイトルにタイトルを設定する方法は、カテゴリの配列にあるため、セクションごとに配列の場合です。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSLog(@"Number of Sections");
if(section == 0)
return @"Sales";
if(section == 1)
return @"Soft Skills";
}
tableView セルにデータを表示するには、すべてのカテゴリの配列を作成できますか?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section==0)
{
appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
int count=[resultArray count];
NSLog(@"resultArry Row Counts is %d",count);
return [resultArray count];
}
else{
appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
int count=[resultArrayOne count];
NSLog(@"resultArry Row Counts is %d",count);
return [resultArrayOne count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Table Cell Data");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (indexPath.section==0) {
appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
ObjectData *theCellData = [resultArray objectAtIndex:indexPath.row];
NSString *cellValue =theCellData.sub_Category;
cell.font=[UIFont fontWithName:@"Helvetical Bold" size:14];
NSLog(@"Cell Values %@",cellValue);
cell.textLabel.text = cellValue;
return cell;
}
else {
appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
ObjectData *theCellData = [resultArrayOne objectAtIndex:indexPath.row];
NSString *cellValue =theCellData.sub_Category;
cell.font=[UIFont fontWithName:@"Helvetical Bold" size:14];
NSLog(@"Cell Values %@",cellValue);
cell.textLabel.text = cellValue;
return cell;
}
}