views:

17

answers:

1

It is my fervent dream to have a UITableView with different row sizes, determined programmatically. I have read the UITableViewDataSource documentation, and I implement these methods:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

which, we can see here:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (CGFloat) 200.0f;
}

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell* test = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil ];

    test.textLabel.text = @"TEST";

    CGRect ffframe = test.frame;

    ffframe.size.height *= 200.0f;

    test.frame = ffframe;

    return test;        
}

These are just trying to make a simple table, with one row, and a height of 200.0. I try to return the height in the delegate method, and set it explicitly. Neither works.

I try trapping the heightForRow method in the debugger, it seems to never be called.

MY table rows are always the size I set in interface builder.

I have the datasource hooked up right, otherwise it would not get the rows and textLabel right.

I built a test app to specifically test this, and I am at a loss as to what I am doing wrong. It seems pretty straightforward...

+1  A: 

This is a delegate method so ensure that you have

self.tableview.delegate = self;

in viewDidLoad or else have the tableview delegate property in the xib linked up to the controller.

Liam
Yes, that is the solution. Why it's a delegate method not a datasource method seems weird. But as soon as I set the delegate it works.
Tom Schulz