1
votes

I have UITableView and I have set height of tableview to 308. For each cell, they are of size 154 as shown in screenshots.

enter image description here

Now when I run this and I have 3 rows in UITableView. I was expecting to remain height as 308 only and expecting to have scrolling option. On scrolling I will see row 3 also, however UITableView is behaving differently. It is taking whole screen as shown below.

enter image description here

If you see, I can see third row and height of the row is increased.

To adjust height if tableview, I added below code in viewWillAppear,

mainTableView.frame = CGRectMake(mainTableView.frame.origin.x, mainTableView.frame.origin.y, 320, 308);

When I run this first time, I see all three rows. WHen I try to add and comes back to Home screen, I now see two rows only. But the problem is when I scroll, it crashes.

Crash says

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]'

But this is not actual problem. If this is problem, then it should have also been crashed when I go to HomeViewController for the first time.

Any suggestion how should I solve this UITableView problem?

1

1 Answers

0
votes

Your springs and struts are configured to autoresize the UITableView to fit the screen height and width. If you only need to table view to be 308px in height disable the vertical arrow in the "View" section of the interface builder when the table view is selected. Also as far as your problem goes it looks like you don't have the clipsToBounds property enabled for the table view.