1

I am trying to remove these tablecells which I am not using but don't know how. I already specified how many cells I want but these unwanted one keep showing, like so;

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

enter image description here

anyone know how to solve this? thanks in advance

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if ([self numberOfSectionsInTableView:tableView] == (section+1))
{
    return [UIView new];
}
return nil;

but to no avail as i get a sigabrt error..why is that ?

DanKiiing
  • 102
  • 1
  • 11
  • 1
    possible duplicate of [Eliminate Extra separators below UITableView - in iphone sdk?](http://stackoverflow.com/questions/1369831/eliminate-extra-separators-below-uitableview-in-iphone-sdk) – jrturton Nov 15 '12 at 07:58
  • thanks jrturton, it indeed is the same issue, thanks for pointing that to me. I tried this code '- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { if ([self numberOfSectionsInTableView:tableView] == (section+1)) { return [UIView new]; } return nil;' – DanKiiing Nov 15 '12 at 10:15

6 Answers6

1

I personally solved it using :

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}

Instead of viewForFooterInSection:.

rdurand
  • 7,342
  • 3
  • 39
  • 72
  • thanks for the input but i updated the question with my answer, try it out and let me know what you think, it appears to be the cleanest way to do it. @rdurand – DanKiiing Dec 11 '12 at 11:17
  • Why did you post an accept your own answer ? You just accepted exactly what I said ! You should remove your answer and accept mine if it solved your problem. You're just creating duplicates of the same answer and will get downvoted for this. – rdurand Dec 11 '12 at 12:01
  • my answer worked for me thats why i voted for it and i believe yours would probably do also, thus I voted for it. it's not duplicates as it's slightly different answers, I don't see what the big deal is in having different ways to carry out a method being voted, they would come in handy for people so I don't know why I im being down voted. I am just here to learn, oh well – DanKiiing Dec 12 '12 at 11:02
  • I don't see anything different between my answer and what you posted. And btw, I'm not the one who down voted you ;) – rdurand Dec 12 '12 at 13:28
0

try this

 - (void) addFooter
 {
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];

[self.myTableView setTableFooterView:v];

[v release];
}

You can try different options from

Eliminate extra separators below UITableView

Community
  • 1
  • 1
Ramz
  • 596
  • 1
  • 6
  • 23
  • thanks for the input but i updated the question with my answer, try it out and let me know what you think, it appears to be the cleanest way to do it. – DanKiiing Dec 11 '12 at 11:15
0

You have two options to do this.

  1. Set tableView style to Grouped (UITableViewStyleGrouped)
  2. Return the cell height like tableViewHeight/number of cells from heightForRowAtIndexPath: method:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
     {
       int tableViewHeght = 720;
        return tableViewHeght * 3;
     }
    
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • thanks for the input but i updated the question with my answer, try it out and let me know what you think, it appears to be the cleanest way to do it. – DanKiiing Dec 11 '12 at 11:15
0

You can do Like this also

1.create a one one UITableCell class and Append that class to UITableView. 2.And your UITableView Attributes Change BackGroundColour is ClearColour

Then you can run And Show

For your reference you can use BackGround image also

sabir
  • 626
  • 7
  • 19
  • thanks for the input but i updated the question with my answer, try it out and let me know what you think, it appears to be the cleanest way to do it. – DanKiiing Dec 11 '12 at 11:13
0

I have seen answers as to use a header/footer or try using a grouped table view, all seems good and also the cleaner solutions. But I would rather opt another one. Assign your table view separator style to none. Declare an UIImageView instance in your cellForRowAtIndexPath method. Make an image of height 1px, width 320px, set it as the image of the image view, and add it as subview of cell, the y position being height of the cell. Do remember to autorelease the image view instance. Since autoreleasing of the same is done, there wont be any memory issues, and also you could decide in which all cells you have to show it, thereby making it a bit more flexible.

Feby Sam
  • 793
  • 1
  • 6
  • 14
-1

I was able to solve the issue by having this in my code;

 - (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// This will create a "invisible" footer
return 0.01f;
 }

Hope this helps someone, peace!

DanKiiing
  • 102
  • 1
  • 11