UITableviewCell行和标题是两个不同的数组

时间:2017-05-04 06:31:52

标签: ios objective-c uitableview uitableviewsectionheader

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

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

UI完美运行,标题和部分的值也很好,但每个部分的行值看起来都相同。

1 个答案:

答案 0 :(得分: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

    }