【问题标题】:how to change the size of tableView in tableView controller如何在 tableView 控制器中更改 tableView 的大小
【发布时间】:2013-02-14 11:46:11
【问题描述】:

我创建了一个拆分视图控制器,我想减小表视图的大小,但它内置了 tableView 控制器,所以有没有办法从代码中更改表的大小意味着我只有 4 行,它得到splitViewController 的所有方面我都想减小 tableViewController 的大小。 在 My Root 控制器中,它是 tableViewController,所以任何方法都可以解决这个问题。

我还附上了表格图像下方的图像,因为它只有三个记录,所以我希望它必须只显示三行,它也显示空行。

【问题讨论】:

    标签: iphone xcode ipad uitableview


    【解决方案1】:

    你可以在UITableView的这个委托方法中设置每一行的高度:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
    

    一旦你设置了高度,你就必须reload你的桌子。

    编辑:

    - (void) viewDidLoad
    {
      [super viewDidLoad];
    
      self.tableView.tableFooterView = [[[UIView alloc] init] autorelease];
    }
    

    【讨论】:

    • 你能解释一下如何解决这个问题吗?它会解决这个问题吗
    • 它只是改变单元格高度而不是表格高度
    • @NaziaJan : 你想去掉那些多余的白线吗?
    • @NaziaJan 只需将您的 UITableView 样式更改为 UITableViewStyleGrouped
    • @NaziaJan 我已经编辑了我的答案。添加我在 viewDidLoad 中提到的代码并检查。
    【解决方案2】:

    您可以添加此代码。这不会在您的 UITableView 中显示额外的行

    - (void) addFooter
    {
        UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
    
        [self.myTableView setTableFooterView:v];
    
        [v release];
    }
    

    你也可以通过这个设置你的行高

     - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
      //Set height according to your condition
      if (indexPath.row == 0)
      {
      }
      else
      {
      }
    }
    

    然后你可以重新加载你的UITableView

    [tableview reloadData];
    

    编辑:- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section中调用函数addFooter

    你也可以添加这个

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

    【讨论】:

    • 在哪里调用 add Footer 方法,之后我可以重新加载代码
    • 如果你在委托方法中设置了该函数的高度,那么不需要重新加载tableview,只有当你要加载tableview的内容时,你才能使用任何函数的reload。
    猜你喜欢
    • 2020-06-15
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多