0

I have two array. One for Tableview Header and another one for Tableview row. I want to display header wise values for different Rows. Number of sections are depend on that array which is used in Header view.

Number of rows is calculated tableview row array divide by header array.

The UI working perfectly and also values of header and sections are fine but row values appear same for each and every section.

VivekBoom
  • 33
  • 1
  • 5
  • Can you add the relevant code? – jarora May 04 '17 at 06:33
  • -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [arrAttendanceResult count]/[arrAttendanceHeader count]; } – VivekBoom May 04 '17 at 06:35
  • -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if([strTeamType isEqualToString:@"Team Attendance"]){ NSLog(@"HEADER COUNT: %lu",(unsigned long)[arrAttendanceHeader count]); return [arrAttendanceHeader count]; } } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [arrAttendanceHeader objectAtIndex:section]; } – VivekBoom May 04 '17 at 06:35
  • In cellforatindexpath: TeamAttendance *objTeamAttendance = [[TeamAttendance alloc] init]; objTeamAttendance = [arrAttendanceResult objectAtIndex:indexPath.row]; – VivekBoom May 04 '17 at 06:37
  • Separate those array: NSString *strDemo=@""; for (TeamAttendance *obj in arrTeamAttendance) { if(![obj.strEmpNameTeamAttendance isEqualToString:strDemo]) { NSString *strName = [NSString stringWithFormat:@"%@ - %@ - %@",obj.strEmpNameTeamAttendance,obj.strEmpCodeTeamAttendance,obj.strBranchTeamAttendance]; [arrAttendanceHeader addObject:strName]; strDemo = obj.strEmpNameTeamAttendance; } [arrAttendanceResult addObject:obj]; } – VivekBoom May 04 '17 at 06:39
  • @VivekBoom Please edit your question with code and don't post it in the comments. – Lepidopteron May 04 '17 at 07:05
  • hi , can you show the data in Row array – Ajjjjjjjj May 04 '17 at 07:05
  • if you are using same Row array for all sections then how can you get different result – Ajjjjjjjj May 04 '17 at 07:24

1 Answers1

0

yo have to use this Approach to show different Cell Result

  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return _mutableArray.count;
    }    


    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(5, 0, tableView.frame.size.width, heightOfSection)];
          NSDictionary *dict =   [_mutableArray objectAtIndex:section];
         NSString *useIt=   [dict objectForKey:@"CategoryName"]
       return  view;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

          NSDictionary *dict =   [_mutableArray objectAtIndex:section];

        NSArray *array= [dict objectForKey:@"FontNames"];

        return array.count;
    }



    - (UITableViewCell *)tableView:(UITableView *)tableViewLocal cellForRowAtIndexPath:(NSIndexPath *)indexPath{

     //   static NSString *cellIdentifier = @"Cell";

        UITableViewCell *Cell = [tableViewLocal dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];


        for (__strong UIView *view in Cell.contentView.subviews) {
            [view removeFromSuperview];
            view = nil;
        }

       // [tableViewLocal setAllowsSelection:NO];

       /* UILabel *labelDetailName =[[UILabel alloc]init];

        labelDetailName.frame =CGRectMake(5, 15, 300, 40);

        NSDictionary *dict =  [_mutableArray objectAtIndex:(tableViewLocal.tag-100)];

        NSArray *arrayLocal = [dict objectForKey:@"FontNames"];


        NSString *titleName =[ [arrayLocal objectAtIndex:indexPath.item]objectForKey:@"title"];

        labelDetailName.text = titleName;

        NSString *fontName = [[arrayLocal objectAtIndex:indexPath.item] objectForKey:@"nameForSystem"];

        labelDetailName.font = [UIFont fontWithName:fontName size: kSystemVersion < 7.0 ? 20 : 16];

        [Cell.contentView addSubview:labelDetailName];  */







        NSDictionary *dict = [_mutableArray objectAtIndex:(tableViewLocal.tag-100)];
        NSArray *Array =  [dict objectForKey:@"FontNames"];


        NSString *localString = [Array objectAtIndex:indexPath.row];  // use it

    }
Ajjjjjjjj
  • 669
  • 4
  • 12