-1

in table i am setting the height for cell using(heightForRowAtIndexPath)delegate of table view the code is:

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

but i am checking the size of cell in delegate method(cellForRowAtIndexPath) and code is:

 - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Dequeue or create a cell
UITableViewCellStyle style =  UITableViewCellStyleDefault;
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:@"BaseCell"];
if (!cell) 
    cell = [[UITableViewCell alloc] initWithStyle:style reuseIdentifier:@"BaseCell"] ;

cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", numberOfItems - indexPath.row];
    NSLog(@"%f",cell.frame.size.height);
 return cell;
  }

when i am printing the value(frame of cell)cell on console its giving me 44.00.why this is happening even i am setting height of cell..please explain me and what to do to get the cell oh height 100..thanks in advance

actually i want to make custom type table view which support difrrent orientation of view and it is universal app so it will better to call the cell size in behalf of checking every time (iphone/ipad,diff orintation)....plz help me to accomplish requirement

Stefan
  • 5,203
  • 8
  • 27
  • 51

3 Answers3

1

If the cell is being shown correctly, and by correctly I mean with a height of 100 pixels as you have written in your tableView:heightForRowAtIndexPath:, I'm pretty sure it's because you're asking for the cell's height in the wrong place: the cell has just been init'd with the default init method, the height returned is therefore the default one, of 44 pixels as nslog prompts in your console, on rendering the delegate sets the right height returned from your method and everything is set up correctly.

I had this issue months ago, for some reasons I needed to know cell's height in the tableView:cellForRowAtIndexPath: method, I came out with a workaround for that: I've stored all rowHeights values in an NSArray, since they were dynamic and different row by row according to their content.

I came out with something like

CGFloat height = [[heightsData objectAtIndex: indexPath.section] objectAtIndex: indexPath.row];

dev_mush
  • 2,136
  • 3
  • 22
  • 38
  • You are thinking to complicated. Just ask your tableViewDelegate for the height. `CGFloat height = [self tableView:tableView heightForRowAtIndexPath:indexPath];` – Matthias Bauch Sep 04 '13 at 13:05
  • but always asking for cell size is it reliable – kamalesh kumar yadav Sep 04 '13 at 13:23
  • Yes @MatthiasBauch you're right, my Implementation was due to performance needs since I had to made many calculations for the correct row height, with this "array of heights" I do it once at VC load time, but if the height is easily calculated your implementation is far way cleaner and easier than mine. – dev_mush Sep 04 '13 at 16:11
0

Do you have set your delegate for UITableViewDelegate ?

Try to put any log in your tableView:heightForRowAtIndexPath: method at first to see if your delegate is set.

Ticko
  • 368
  • 1
  • 2
  • 11
0

hi friends dev had given explanation

  NSLog(@"%f",[self tableView:tableView heightForRowAtIndexPath:indexPath]);
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Dilip Manek Sep 04 '13 at 13:45
  • yes the above is not fully corect (as per requirement)but it is workable – kamalesh kumar yadav Sep 04 '13 at 13:49
  • Where to call this method `[self tableView:tableView heightForRowAtIndexPath:indexPath]`? And For what? I have cell where each of them have different height. – Geek Jan 31 '14 at 05:40