-1

I keep having the problem that my tableview controller always displays a lists of cells and only the first two have any data in them. Is this normal? Is it possible to have a tableview controller display only two cells (that is, the ones that have the data in them)?

In other words, the first two cells say "blah" and "blah2". All the others are blank. I know that the number of sections is 1 and the number of rows in the section is 2. I still get the first two cells displayed correctly and the rest are blank. Is this normal? How can I just display two cells?

jscs
  • 63,694
  • 13
  • 151
  • 195
user678392
  • 1,981
  • 3
  • 28
  • 50
  • show us some code to analyse.. – Saurabh Passolia Jul 07 '13 at 18:20
  • maybe you mean separator line between cells? You want to hide them? – stosha Jul 07 '13 at 18:32
  • @stosha Not sure what you mean. All I know is that I see a whole page of what looks to be blank cells. – user678392 Jul 08 '13 at 13:02
  • @samfisher this is more of a conceptual question. you shouldn't need code. What I'm asking is that if you tell the tableview that you have only 2 items, what is the best way to display two items ando only two items, not two items and a whole page of blank cells. – user678392 Jul 08 '13 at 13:04
  • Same question Asked here..See the link http://stackoverflow.com/questions/14520185/ios-uitableview-displaying-empty-cells-at-the-end – shyam Sep 21 '13 at 05:10

2 Answers2

0

it is not the table view controller that displays the cell. it is the table view.

you could add a tableview as subview to a view controlled by a view controller and set it frame with a height that is enough to display both cells.

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • So what you are saying is that there is no way to just tell the tableview to display just two cells without specifying the height of the frame? This seems hard to believe. – user678392 Jul 08 '13 at 13:03
  • the table view displays the cell, but doesn't the table view controller tell the table view things, like, how many cells to display? Cheers. – user678392 Jul 08 '13 at 13:07
  • Sure, it controls the view — hence the naming. But I propose that you use a viewcontroller subclass and implement the delegate and data source there, as it will give you the option to display the table view as subview with custom dimensions. – vikingosegundo Jul 08 '13 at 13:19
  • The other option would be to roll out a complete customized style by recreating the background images and separators. – vikingosegundo Jul 08 '13 at 13:21
  • Third option: subclass uitableview and overwrite `layoutSubviews` — but might be quite complex to explore apples undocumented view hierarchy. – vikingosegundo Jul 08 '13 at 13:26
  • A fourth option: add a footer of a size that it fill the space. – vikingosegundo Jul 08 '13 at 13:29
0

Another option, set the style of the UITableview to grouped and have only one section. It will display only the number of cells you tell it in the method numberofrows:section.

user678392
  • 1,981
  • 3
  • 28
  • 50