0

我有两个数组。一个用于 Tableview 标题,另一个用于 Tableview 行。我想显示不同行的标题明智值。部分的数量取决于在标题视图中使用的数组。

行数由表视图行数组除以标题数组计算得出。

UI 运行良好,标题和部分的值也很好,但每个部分的行值都相同。

4

1 回答 1

0

你必须使用这种方法来显示不同的单元格结果

  - (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

    }
于 2017-05-04T06:59:41.760 回答