TableView heightForRowAtIndexPath按标记

时间:2015-09-21 14:33:57

标签: ios objective-c uitableview

我创建了一个自定义的TableView(创建内部故事板),有些行有33个高度,78个高度,204个高度。当我运行我的项目时,行的高度与我绘制的不同。

为了解决这个问题,我在表格的每一行上放了一个标签,并使用以下命令:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    switch (indexPath.row) {
        case 0:
            return 56;
            break;

        case 1:
            return 44;
            break;

        case 2:
            return 34;
            break;

        case 3:
            return 172;
            break;

        default: return 204;
            break;
    }

}

但是这段代码有问题,我需要检查 indexPath.row.tag 而不是 indexPath.row (当我尝试使用.tag Xcode don&#39 ; t编译)

如何按标签选择行?或者我怎样才能使线条的高度与我设计的相同(不使用命令:heightForRowAtIndexPath)?

修改

  menuItems = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52"];

        - (UITableViewCell *)tableView:(UITableView *)tableView2 cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
            UITableViewCell *cell = [tableView2 dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }

            return cell;
        }

0 个答案:

没有答案