Unwanted Tablecells showing

时光总嘲笑我的痴心妄想 提交于 2019-12-11 11:26:29

问题


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;
}

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 ?


回答1:


I personally solved it using :

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

Instead of viewForFooterInSection:.




回答2:


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:


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;
     }
    



回答4:


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




回答5:


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.




回答6:


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!



来源:https://stackoverflow.com/questions/13391615/unwanted-tablecells-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!