删除tableview的额外部分或额外底部空间

时间:2018-03-28 11:19:46

标签: objective-c uitableview

enter image description here

我创建了一个简单的tableview,其中我遇到了一个问题,即在正确显示所有部分之后,我想删除几个虚拟部分但是为什么它们被显示我无法找到

这里每个部分下的部分计数和行数都是正确的。

那么你们可以建议如何删除额外的空间并获得原始的表格内容大小吗?

以下是我在.m文件中专门为tableview

完成的代码
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  // Return the number of sections.
  if (searchEnabled)
  {
    return 1;
  }
  else
  {
    return tableDataArray.count;
  }
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   UILabel *headerView;
  [headerView setBackgroundColor:[UIColor colorWithRed:216.0/255.0 green:216.0/255.0 blue:216.0/255.0 alpha:0.5]];
  for (int i=0; i<alphabetArray.count; i++)
  {
    if (section==i)
    {
        headerView.text= [alphabetArray objectAtIndex:i];
        headerView.textColor = [UIColor blackColor];
        headerView.font = [UIFont fontWithName:@"Montserrat-Medium" size:12.0];
    }
  }
  return headerView;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
  if (searchEnabled)
  {
    return nil;
  }
  else
  {
    NSString *title;
    for (int i=0; i<alphabetArray.count; i++)
    {
        if (section==i)
        {
            title= [alphabetArray objectAtIndex:i];
        }
    }
    return title;
 }
}
-(NSMutableArray *)getArrayOfRowsForSection:(NSInteger)section
{
  NSString *rowTitle;
  NSString *sectionTitle;
  NSMutableArray *rowContainer=[[NSMutableArray alloc]initWithCapacity:0];

  for (int i=0; i<alphabetArray.count; i++)
  {
    if (section==i)   // check for right section
    {
        sectionTitle= [alphabetArray objectAtIndex:i];  //getting section title
        for (NSString *title in tableDataArray)
        {
            rowTitle=[title substringToIndex:1];  //modifying the statement to its first alphabet
            if ([rowTitle isEqualToString:sectionTitle])  //checking if modified statement is same as section title
            {
                [rowContainer addObject:title];  //adding the row contents of a particular section in array
            }
        }
    }
  }
  return rowContainer;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  // Return the number of rows in the section.
  if (searchEnabled)
  {
    return [self.searchResult count];
  }
  else
  {
    NSMutableArray* rowArray=[[NSMutableArray alloc]init];
    rowArray=[self getArrayOfRowsForSection:section];
    return rowArray.count;
  }
 }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

  if (cell == nil)
  {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  }
  if (searchEnabled)
  {
    cell.textLabel.text = [self.searchResult objectAtIndex:indexPath.row];

  }
  else
  {
    NSMutableArray* rowArray=[[NSMutableArray alloc]init];
    rowArray=[self getArrayOfRowsForSection:indexPath.section];
    NSString *titleToBeDisplayed=[rowArray objectAtIndex:indexPath.row];
    cell.textLabel.text = titleToBeDisplayed;
  }
  cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
  return cell;
}

2 个答案:

答案 0 :(得分:0)

很难从代码中得到理由(似乎没关系)。请检查故事板中你的 UITableViewStyle 是什么。如果它很简单,那就试试吧:

{
    "AUD": ["aud1", "aud2"]
}

答案 1 :(得分:0)

试试这个

- (void)viewDidLoad {
  self.tblView.backgroundColor=[UIColor clearColor];
}

并在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor=[UIColor clearColor];
}
相关问题