Unwanted Tablecells showing

2019-07-31 13:46发布

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 ?

6条回答
虎瘦雄心在
2楼-- · 2019-07-31 14:28

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

查看更多
啃猪蹄的小仙女
3楼-- · 2019-07-31 14:29

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.

查看更多
干净又极端
4楼-- · 2019-07-31 14:31

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;
     }
    
查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-07-31 14:34

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

查看更多
男人必须洒脱
6楼-- · 2019-07-31 14:34

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!

查看更多
不美不萌又怎样
7楼-- · 2019-07-31 14:35

I personally solved it using :

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

Instead of viewForFooterInSection:.

查看更多
登录 后发表回答