iosobjective-cuitableviewheightforrowatindexpath

Not possible to setup UITableViewCell height


Please, help me to setup UITableViewCell height.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    UILabel *l0, *l1;
    if (cell == nil) {

        CGRect f = tableView.frame;
        float sc0 = pow(dt.PHI_1, 3.f);
        float sc1 = 1. - sc0;

        CGRect z =CGRectMake(0, 0, 0, 0);//f.size.height
        CGRect r =CGRectMake(0, 0, f.size.width, f.size.height / 26.f);
        CGRect r0 =CGRectMake(0, 0, f.size.width * sc0, f.size.height / 26.f);
        CGRect r1 =CGRectMake(f.size.width * sc0, 0, f.size.width * sc1, f.size.height / 26.f);

        cell = [[UITableViewCell alloc] initWithFrame:r]
        l0 = [[UILabel alloc] initWithFrame:r0];
        l0.tag = 100;
        [cell addSubview:l0];
        l1 = [[UILabel alloc] initWithFrame:r1];
        l1.tag = 101;
        [cell addSubview:l1];
        [cell.textLabel setFrame:z];
        [cell.imageView setFrame:z];
        [cell setFrame:r];
        [cell.backgroundView setFrame:r];
    } else {
        l0 = (UILabel *)[self.view viewWithTag:100];
        l1 = (UILabel *)[self.view viewWithTag:101];
    }
    cell.backgroundColor = [[UIColor alloc]initWithWhite:.0f alpha:0.f];

    cell.imageView.hidden = YES;
        cell.textLabel.hidden = YES;
        [l0 setText:@"B"];
        l0.backgroundColor = [UIColor yellowColor];

        [l1 setText:@"TEXT"];
        l1.backgroundColor = [UIColor redColor];

        return cell;
}

this code gives this:

enter image description here

method like this did not help me:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGRect f = tableView.frame;

    return f.size.height / 26.f;
}

SO, if I setup the height smaller. That is, f.size.height / 26.f I have a transparent bar.

UITableView definition:

table = [[UITableView alloc] initWithFrame:CGRectMake(x,y,w,h)];
table.dataSource = self;
[table setTag:1];
[self.view addSubview:table];

Please, provide me a way to setup cell height. If I set very big height of UITableViewCell it is not modified too - only the top part is shown.


Solution

  • Thanks to everyone. I found the solution.

    1. Use storeboard to declare UITableView
    2. Use the below code to define the height.

    the code:

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            CGRect f = tableView.frame;
            return f.size.height / 26.f;
        }
    

    I do not understand but it didn't work when I declared the table programmatically.